Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python - variables, syntax and text manipulation

Total questions: 40

Worksheet time: 22mins

Name
Class
Date
1.

The correct syntax of the len function to return the length of the variable x:

a)

x.len()

b)

len[x]

c)

LEN[]

d)

len(x)

2.

The correct syntax for converting the variable x to uppercase is :

a)

X.upper()

b)

upper(x)

c)

x.UPPER[ ]

d)

x.upper()

3.

The correct syntax for converting the variable myname to lowercase is :

a)

myNAME.lower[ ]

b)

myname.lower( )

c)

myname.upper( )

d)

myname_lower(12 )

4.

Let x= "Python", the output of print(x.upper()) is

a)

python

b)

PYTHON

c)

_PYTHON

d)

"PYTHON"

5.

Let x= "Python", the output of

print(x[0])

print(x[1])

print(x[2])

a)

PYT

b)

P

y

t

c)

T

h

o

d)

n

oh

6.
What letter will be printed on the screen after running this code:
a)
e
b)
x
c)
t
d)
Nothing prints
7.
In the following code, "city" is an example of a what?
a)
List
b)
Loop
c)
Variable
d)
Array
8.
What output will this code produce?
a)
Exeter
b)
4
c)
6
d)
city
9.

For text, the + operator represents

a)

Concatenation

b)

Addition

c)

Appending

d)

Recantation

10.

data = "No Way!"
The code print(len(data)) would output:

a)

7

b)

9

c)

8

d)

6

11.

What will the output be from the following code?

print("Hello world!" * 2)

a)

TypeError

b)

Hello world world!

c)

Hello world!Hello world!

d)

Hello world! * 2

12.

What will the output be from the following code?

print("3+4")

a)

7

b)

34

c)

3+4

d)

SyntaxError

13.

print("12"*3)

What would this print?

a)

121212

b)

36

c)

24

d)

12*3

14.
What will the output be from the following code?
print("Hello" + "world" + "today")
a)
Helloworldtoday
b)
Hello world today
c)
"Hello" "world" "today"
d)

Syntax Error

15.
What will the output be from the following code?
print(Hello world!)
a)
Hello world!
b)

Syntax Error

c)
Hello world
d)
print(Hello world!)
16.
What will the output be from the following code?
print("Hello world!")
a)
SyntaxError
b)
Hello world!
c)
"Hello world!"
d)
print(Hello world!)
17.
What will the output be from the following code?
Print("Hello world!")
a)

Syntax error

b)
Hello world!
c)
"Hello world"
d)
Print(Hello world!)
18.

Which function takes allows the user to enter data into the program?

a)
print()
b)
int()
c)
input()
d)
def
19.

Each item in a word has an "address" or index. The first index in a Python string is what?

a)

0

b)

1

c)

a

d)

A

20.

What symbol do you use to declare a comment in Python?

a)
@
b)
¬
c)
;
d)
#
21.

What character will be printed on the screen after running this Python code:

a)

a

b)

l

c)

L

d)

Nothing is printed

22.

What output will this Python code produce?

a)

Kuala Lumpur

b)

11

c)

12

d)

x

23.

What will this print to the screen?


print(2*4)

a)

2*4

b)

8

c)

4

d)

error

24.

What will be printed to the screen?

a)

5

b)

10

c)

5 + 10

d)

15

25.

Num = 90

Num = 20

print(Num)

a)

90

b)

4.5

c)

20

d)

1800

26.
What does the print function do in python?
a)
It's a variable.
b)
It can input data.
c)

It displays an output message

27.

What is the definition for a VARIABLE?

a)

It stores a value within a program that can change

b)

It allows the algorithm to make a selection

c)

It is a set of precise instructions to solve a problem

d)

It stores a value within a program which stays the same

28.

Choose all rules for naming a variable from the list below:

a)

Must not begin with a number

b)

Can only contain (A-Z, a-z) and 0-9 characters, and _

c)

It can't contain a space

d)

Must be in lower case

29.

Choose all valid variable names from the list of options given below:

a)

1st_name

b)

Last_name

c)

first Name

d)

f1_name

e)

firstName

30.

Which of the below are acceptable variable names?

a)

result final = 5

b)

result-final = 1

c)

resultFinal = 3

d)

result#final = 4

31.
The correct way to write a variable in Python?
a)
myVariable = 10
b)
my Variable = 10
c)
myVariable is 10
d)
myVariable: 10
32.

What is the name of the variable in this program?

a)

print

b)

colour

c)

input

d)

" "

33.

print("Python " * 3); will print out what

a)

Python 3 Python 3 Python 3

b)

Python Python Python

c)

PythonPythonPython

d)

Python*3 Python*3 Python*3

34.

Which of the following statements assigns the value 100 to variable x in python

a)

Let x=100

b)

x=100

c)

x:=100

d)

x==100

35.

What will be output of the following code be?

1var = 6

a)

6

b)

1

c)

var

d)

Syntax error

36.

What will the output of the following code be?

a = 5

b = 0

print(a)

a)

5

b)

0,5

c)

0

5

d)

5

5

37.

What symbol is used for multiplication in Python coding?

a)

x

b)

+

c)

#

d)

*

38.
What will the output be from the following code?
print(3+4)
a)
3+4
b)
7
c)
SyntaxError
d)
print(3+4)
39.
What will the output be from the following code?
print("3+4")
a)
7
b)
3+4
c)
34
d)
SyntaxError
40.

What will be the output?

name = "Dave"

print ("name")

a)

Dave

b)

"Dave"

c)

name

d)

(name)