Professional Documents
Culture Documents
Lecture 2
Lecture 2
Sherina Sally
OUTLINE
• Python Indentation
• Python Keywords
1
INDENTATION IN PYTHON
• Use the same amount of spaces for all the lines in the block
STATEMENTS
• Instructions which the Python interpreter can execute
• Multiple simple statements can occur in a single line: separate using (;)
2
STATEMENTS …(2)
if x > 1:
x = 10 y = “Hello ” \ print(“X is greater than 1")
“I’m Ann. ”\ else:
Simple statement “What is your name ? ” print(“X is less than 1")
Multi-line statement
COMMENTS
• Increase understandability of a program
# can be denoted
# as a single line comment
• No explicit way of denoting a multi-line comment
# in multiple lines
• Use multiple single line comments
• Use triple single quotes (‘ ‘ ‘ ) or triple double quotes (“ ” ”) ‘’’ This is another way
to denote a
multi-line comment ‘’’
3
RESERVED KEYWORDS
USER INPUTS
• User inputs are important when the program needs values externally
4
DISPLAY OUTPUT
• Outputs that are intended to display by the program to the console
a = “Micheal”
print(“ First program of “, a)
Type of conversion
All Rights Reserved
5
FORMATTED OUTPUT …(2)
<type> Conversion Type
print(“%4.2f“ %(3.235)) d, i, u Decimal integer >>> print(“ %3d “ %1)
x, X Hexadecimal integer
o Octal integer