Python 3 latest code crumbs
Convert strings to numbers by using a list comprehension
Apr 12, 2022 by erik
Convert the numerical strings in the list numbers
into actual numbers (integers) by using a list comprehension. If you need a little guidance, make sure to read my article on list comprehensions first....
Return the last element of a Python list
Apr 5, 2022 by erik
Finish the function so it returns the last element of the given list. You may assume the list is not empty....
Demonstration of how a Python range works
Mar 6, 2022 by erik
A range is an iterable object, and this object can return an iterator that keeps track of its current state. Suppose we create a range with the call range(3)
. This returns an object of type range with our requested settings....
Python for-loop using range with start and stop
Mar 6, 2022 by erik
We don't always want to start counting at zero, and that's why we can also call range
with both a start and stop value. A call to range(2, 5)
will return the values 2, 3, and 4....
Python for-loop with range (with one argument)
Mar 6, 2022 by erik
If we call Python's range
with one argument, that argument is the stop value. In this case, range
will start counting at 0 until it reaches the stop value. For example, if we call range(5)
, the created range object will...