24-RTSA-01 Introduction to Python
24-RTSA-01 Introduction to Python
• More in detail:
• First, the Python source code is read by a Python interpreter
o Checks if the code is syntactically correct
o Converts it into ByteCode
• Then, the Python Virtual Machine (PVM) execute the code
• Everything is an object
• A variable can refer to a value of type x, and later can refer to an value of
type y
# Ex. 2:
a = 'goofey'
a = a – 2
print(a)
MAX = 10 # constant
min = 0 # variable
name1 value1
name2 value2
name3 value3
A=10
• input() is an expression
• It is used to transfer values from the external to the internal state
• input() always gives values of type str
c=input() # assignment: d is the name, input() is the expression
• Expressions are
• completely evaluated
• from left to right
• respecting the precedence rules of math
• parentheses may be used to force grouping
• Even if two cars are completely identical, they remain two separate cars
• They have the same Data Type (car)
• They have the same value (the brand and model of the car)
• But they are two different objects, and therefore have two different
identities (the plates are different)
• The comparison operator is can be used to test if two objects have the
same identity (and therefore are the same object)
• For now, identity doesn’t seem very important, we will see it actually is
• Blocks in Python:
• a sequence of lines
• each line with a single command
• all of them at the same indentation
o same distance from the left margin
o other programming languages use parenthesis {,}.
if a>100:
print('this is block aaa')
print('second instruction of block aaa')
print('third instruction of block aaa')
else:
print('this is block bbb')
print('second instruction of block bbb')
print('third instruction of block bbb')
print('fourth instruction of block bbb')
for i in range(3):
print('Value: ', i)
for i in range(0,10,2):
print('Value: ', i)
• pass
• its execution does nothing;
• it is used to place a placeholder for something that will be added
later
• break
• it is used to interrupt abruptly the iteration
• it will be executed the first instruction following the iteration