0
0
Pythonprogramming~5 mins

Variable assignment in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is variable assignment in Python?
Variable assignment means giving a name to a value so you can use it later. For example, x = 5 means the name x now holds the value 5.
Click to reveal answer
beginner
How do you assign multiple variables in one line in Python?
You can assign multiple variables by separating them with commas. For example, a, b = 1, 2 assigns 1 to a and 2 to b.
Click to reveal answer
beginner
What happens if you assign a new value to an existing variable?
The old value is replaced by the new one. For example, if x = 5 and then x = 10, x now holds 10.
Click to reveal answer
beginner
Can variable names in Python start with a number?
No, variable names cannot start with a number. They must start with a letter (a-z, A-Z) or an underscore (_).
Click to reveal answer
beginner
What is the difference between = and == in Python?
= is used to assign a value to a variable. == is used to check if two values are equal.
Click to reveal answer
Which of the following is a valid variable assignment in Python?
Ascore = 100
B100 = score
Cscore == 100
Dscore := 100
What will be the value of 'a' after this code? <br> a = 5<br>a = 10
A5
B15
C10
DError
Which variable name is NOT valid in Python?
Avalue_2
B_value
Cvalue2
D2ndValue
How do you assign the values 1, 2, and 3 to variables x, y, and z in one line?
Ax = y = z = 1, 2, 3
Bx, y, z = 1, 2, 3
Cx = 1; y = 2; z = 3
Dx, y, z == 1, 2, 3
What does the '=' symbol do in Python?
AAssigns a value to a variable
BChecks if two values are equal
CStarts a comment
DEnds a statement
Explain how to assign a value to a variable in Python and what rules variable names must follow.
Think about how you give a name to a box and put something inside.
You got /2 concepts.
    Describe what happens when you assign a new value to an existing variable.
    Imagine replacing the content inside a labeled box.
    You got /3 concepts.