wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AI and Python - Variables

Total questions: 9

Worksheet time: 5mins

Name
Class
Date
1.

What should a variable name start with in Python?

a)

Numbers (0-9)

b)

English letters (A-Z, a-z) or an underscore (_)

c)

Punctuation marks

d)

Reserved keywords

2.

Which of the following is a valid variable name in Python?

a)

apple pie

b)

apple_pie

c)

class

d)

123name

3.

What is the purpose of a variable in programming?

a)

Store values

b)

To be used in different operations

c)

The value can be changed

d)

To output the value on the screen

4.

What will the following code print? name = 'Apple' print('name') print(name)

a)

Apple

b)

name

c)

Error

d)

None

5.

Which of the following codes can output "My name is Peter"?

a)

print("My", name, "is", name)

b)

print("My", "name", "is", name)

c)

print("My", name , "is", "name")

d)

print("My", "name" , "is", "name")

6.

In Python, which of the following words can be used as variable names?

a)

first@u

b)

_final_final

c)

IloveU

d)

2B_mark

e)

class2A

7.

What is the output of the following code snippet?
name = "Alice"
print("Hello", name)

a)

Hello, {name}

b)

Hello, Alice

c)

Hello, name

d)

Error

8.

Which of the following is not a valid way to declare a variable in Python?

a)

Var = 5.5

b)

2nd_var = "Hello"

c)

var_2 = True

d)

my_var = 10

9.

What will be the result of the following code?
print("The sum is", 5 + 3)

a)

Error

b)

The sum is 5 + 3

c)

The sum is 53

d)

The sum is 8