Intro To Python Programming
Intro To Python Programming
Introduction
This is a reference handout for the Python elements covered in this unit. The sheets include short
explanations, brief notes, syntax, and selected examples.
Syntax
print(comma-separated literals, variables, expressions)
Examples
Display the string literal
print("Hello world") "Hello world"
Input
The input function reads a line of text from the keyboard and
returns it.
Syntax
input()
Notes
Assign the value returned by input to a variable, if you need to
refer to that value later in your program.
Use the int function to convert the text returned by input to an
integer.
Use the float function to convert the text returned by input to a
floating-point number.
Examples
Read text from the keyboard and
name = input() assign it to the name variable
Syntax
variable name = expression
Notes
Do not interpret the = sign as an equation. Assignments are actions
to be performed.
Read assignments from right to left, i.e. evaluate the expression
and then assign the value to the variable.
A variable name can only refer to a single value. A new
assignment to a variable replaces the previous value of the
variable.
Examples
Assign the string literal "Ada" to the
name = "Ada" name variable
Negation:
not
Examples Conjunction:
and
3 + 13 * 3 Disjunction: An arithmetic expression involving
operators and literals
or