Font size
WorksheetsAI and Python - Variables
Total questions: 9
Worksheet time: 5mins
What should a variable name start with in Python?
Numbers (0-9)
English letters (A-Z, a-z) or an underscore (_)
Punctuation marks
Reserved keywords
Which of the following is a valid variable name in Python?
apple pie
apple_pie
class
123name
What is the purpose of a variable in programming?
Store values
To be used in different operations
The value can be changed
To output the value on the screen
What will the following code print? name = 'Apple' print('name') print(name)
Apple
name
Error
None
Which of the following codes can output "My name is Peter"?
print("My", name, "is", name)
print("My", "name", "is", name)
print("My", name , "is", "name")
print("My", "name" , "is", "name")
In Python, which of the following words can be used as variable names?
first@u
_final_final
IloveU
2B_mark
class2A
What is the output of the following code snippet?
name = "Alice"
print("Hello", name)
Hello, {name}
Hello, Alice
Hello, name
Error
Which of the following is not a valid way to declare a variable in Python?
Var = 5.5
2nd_var = "Hello"
var_2 = True
my_var = 10
What will be the result of the following code?print("The sum is", 5 + 3)
Error
The sum is 5 + 3
The sum is 53
The sum is 8
