






























Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!































Today…
x = 2 print(x) 2 x = 2. print(x)
Simple Assignment Statements: Actual View 2 Before x = 2. 2 After x x
What will happen to value 2?
After x
Memory location will be automatically reclaimed by the garbage collector
name = input("Enter your name: ") Enter your name: Mohammad Hammoud name 'Mohammad Hammoud'
number = input("Enter a number: ") Enter a number: 3 number '3'
Still a string!
number = eval(input("Enter a number: ")) Enter a number: 3. number
And now a float (no single quotes)!
number = eval(input("Enter an equation: ")) Enter an equation: 3 + 2 number
5
The eval function will evaluate this formula and return a value, which is then assigned to the variable “number”
x = 10 float(x)
str(x) '10'
y = "20" float(y)
int(y) 20
z = 30. int(z) 30 str(z) '30.0'
integer float integer string string float string integer float integer float string
x = 2 y = 3 x = y y = x x
3
y 3
CANNOT be done with two simple assignments
x = 2 y = 3 temp = x x = y y = temp x 3 y 2
CAN be done with three simple assignments, but more efficiently with simultaneous assignment Thus far, we have been using different names for variables. These names are technically called identifiers