Download - All IT eBooks

Transcript
Your First Python Program ◾ 35 indentation and is used in Python to mark blocks of code that are executed
together.
Blocks of code occur in loops, conditional statements (see Chapter
4), functions (see Chapter 10), and classes (see Chapter 11). They all are
identified by indentation. A block of code is initiated by a colon character
and followed by the indented instructions of the block. The indentation
length of the first instruction of a block should be four spaces at least,
and all instructions of a block must be indented by the same number of
spaces. Although it is possible to use tabs for indentation, it is advised to
use spaces because tabs lead to problems in some text editors.
2.3.7 Printing to the Screen
The print command is a versatile way of displaying information on the
screen. It writes numbers and text to the text console. You can influence
the way the data are written in many ways. In the most straightforward
way, you simply print the data:
print 7
will print 7 to the screen of your computer, whereas
print 'insulin sequence:'
will simply print insulin sequence:.
Instead of the plain data, you can print a variable:
sequence = 'MALWMRLLPLLALLALWGPDPAAA'
print sequence
will create the output
MALWMRLLPLLALLALWGPDPAAA
You can print multiple values in one command by separating them
with commas:
print 7, 'insulin sequence:', sequence
will print
7 insulin sequence: MALWMRLLPLLALLALWGPDPAAA