concept start in category python

appears as: start, start
Tiny Python Projects: Learn coding and testing with puzzles and games

This is an excerpt from Manning's book Tiny Python Projects: Learn coding and testing with puzzles and games.

>>> word = 'narwhal'
>>> word[0]
'n'

You can index into a literal string value too:

>>> 'narwhal'[0]
'n'

Because the index values start with 0, that means the last index is one less than the length of the string, which is often confusing. The length of “narwhal” is 7, but the last character is found at index 6:

>>> word[6]
'l'

You can also use negative index numbers to count backwards from the end, so the last index is also -1:

>>> word[-1]
'l'

You can use slice notation [start:stop] to get a range of characters. Both start and stop are optional. The default value for start is 0 (the beginning of the string), and the stop value is not inclusive:

>>> word[:3]
'nar'

The song starts at the given --num value, like 10, and needs to count down to 9, 8, 7, and so forth. How can we do that in Python? We’ve seen how to use range(start, stop) to get a list of integers that go up in value. If you give it just one number, that will be considered the stop, and it will assume 0 as the start:

>>> list(range(5))
[0, 1, 2, 3, 4]

Because this is a lazy function, we must use the list() function in the REPL to force it to produce the numbers. Remember that the stop value is never included in the output, so the preceding output stopped at 4, not 5.

If you give range() two numbers, they are considered to be start and stop:

>>> list(range(1, 5))
[1, 2, 3, 4]

To reverse this sequence, you might be tempted to swap the start and stop values. Unfortunately, if start is greater than stop, you get an empty list:

Hello World! Third Edition

This is an excerpt from Manning's book Hello World! Third Edition.

In the Start menu, under Python 3.7, you’ll see IDLE (Python 3.7). Click this option, and the IDLE window will open. It should look something like the window below.

The seek() method makes Python go to whatever place in the file you tell it. The number in brackets is the number of bytes from the start of the file. So setting it to 0 takes it right back to the start of the file.