wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

python gen

Total questions: 45

Worksheet time: 45mins

Name
Class
Date
1.

What is the output of the following code?

a)

10
15

b)

25
125

c)

Error: invalid syntax

2.

What will be the output
?

a)

PythonPython is fun

b)

Error

c)

PythonPythonis fun

d)

PythonPythonis fun

3.

What is the output of the following code?

a)

Python Quiz

b)

PythonQuiz

c)

Python+Quiz

d)

Error

4.

Are the statements below true or false?
*Strings are immutable in Python.

  • -Every time we modify a string, Python always creates a new string and assigns it to that variable.

a)

True

b)

False

5.

What is the Output of the following code?

a)

0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5

b)

0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5

c)

Error: The Program executed with errors

6.

What is the output of the following code?

a)

20

b)

30

c)

 The program executed with errors

7.

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

a)

myvariable

b)

 _my_variable

c)

2myvariable

d)

my_variable2

8.

What is the output of the following code?

a)

py

b)

yt

c)

pyt

d)

yth

9.

How do you add an element to the end of a list in Python?

a)

list.add(element)

b)

list.insert(element)

c)

list.append(element)

d)

list.extend(element)

10.

What is the output of the following code?

a)

Jam

b)

 dno

c)

 maJ


d)

 dnoB semaJ

11.

What is the output of the following code?

a)

D

-space-

r

i

this is else block statement

b)

D

r

i

this is else block statement

c)

D

r

i

n

d)

SyntaxError

12.

What is the output of the following code?

a)

{"Ahmmed","layla", "Salma", "Omar"}

b)

{"layla","Salma", "Omar",1,"Ahmmed"}

c)

The program executed with error

13.

What is the output of the following code

a)

Salary: 12000
Salary: 8000

b)

Salary: 12000
Salary: 12000

c)

 The program failed with errors

14.

What is the output of the following code?

a)

1

b)

2

c)

3

d)

4

15.

What is the output of the add() function call

a)

15

b)

{8, 7}

c)

(8, 7)

d)

Syntax Error

16.

What will be the output of the following Python code?

a)

8

b)

15

c)

Error

d)

multiply

17.

What will be the output of the following Python code?

a)

5

b)

10

c)

None

d)

 Error (Cannot assign to global variable)

18.

What will be the output of the following Python code?

a)

10
0

b)

10
None

c)

Error

d)

10
Error

19.

What will be the output of the following Python code?

a)

15

b)

 Syntax Error

c)

 (5, 10)

20.

What will be the output of the following Python code?

a)

[1, 2, 3]

b)

[1, 2, 3, 4]

c)

[4]

d)

Error

21.

What will be the output of the following Python code?

a)

0 1

Inner loop finished normally

1 0

Inner loop finished normally

Outer loop finished normally

b)

0 1

Inner loop finished normally

1 0

Inner loop finished normally

c)

0 1

Inner loop finished normally

1 0

Inner loop finished normally

Inner loop finished normally

Outer loop finished normally

d)

0 1

1 0

2 0

Outer loop finished normally

22.

What will be the output of the following Python code?

a)

1
2
3

b)

1
3

c)

1
2

d)

Error

23.

What is the value of x

a)

0

b)

8

c)

Error

d)

10

24.

What is the output of the following if statement

a)

False

b)

True

25.

Which list comprehension correctly filters a list numbers to include only odd numbers?

a)

[x for x in numbers if x % 2 ]

b)

[x if x % 2 == 0 for x in numbers]

c)

[x for x in numbers else x % 2 == 0]

d)

[x where x % 2 == 0 in numbers]

26.

What will be the output of the following Python code?

a)

*** ** *

b)

1 22 333

c)

* * * * * *

d)

 * ** ***

27.

What will be the output of the following Python code?

a)

0
1
2
Loop completed

b)

0
1
2

c)

0
1

d)

Error

28.

What will be the output of the following Python code?

a)

1 2
3 4

b)

1 2 3 4

c)

 [1, 2] [3, 4]

d)

 Error

29.

Given the nested if-else structure below, what will be the value of x

a)

2

b)

0

c)

4

d)

3

30.

Select all valid String creation in Python

a)
  • str1 = 'str1'

  • str1 = "str1"

  • str1 = '''str'''

b)
  • str1 = 'str1'

  • str1 = "str1""

  • str1 = '''str1''

c)

 str1 = str(Rund)

31.

What will be the output of the following Python code?

a)

hello

b)

 world

c)

 [‘hello’, ‘world’]

d)

helloworld

32.

Which function is used to convert a string to an integer?

a)

 parse_int()


b)

 to_int()


c)

 int()


d)

 str_to_int()


33.

What will be the output of the following Python code?

a)

1

b)

3

c)

Error

d)

(5,2,3)

34.

What will be the output of the following Python code?

a)

['', 'usr', 'local', 'bin', 'python']

b)

['usr', 'local', 'bin', 'python']

c)

['/usr', '/local', '/bin', '/python']

d)

['/', 'usr', 'local', 'bin', 'python']

35.

What will be the output of the following Python code?

a)

level

b)

True

c)

False

d)

Error

36.

Select the correct output of the following String operations

a)

Error

b)

6

c)

5

37.

What will be the output of the following Python code?

a)

True
True

b)

False
False

c)

True
False

d)

False
True

38.

What will be the output of the following string comparison

a)

True
False

b)

True
True

c)

False
True

d)

False
False

39.

What will be the output of the following string operation?

a)

Welcom Py Sdk

b)

Welcom Py sdk

c)

Elcom Py Sdk

40.

What will be the output of the following Python code?

a)

Joy Joy Joy

b)

 Joy Bliss Joy


c)

 Bliss Bliss Joy


d)

 Joy Joy Bliss


41.

What will be the output of the following Python code?

a)

banana
[‘apple’, ‘cherry’]

b)

banana
[‘apple’, ‘banana’, ‘cherry’]

c)

[‘apple’, ‘cherry’]
banana

d)

Error

42.

What will be the output of the following set operation?

a)

{‘Yellow’, ‘Orange’, ‘Red’, ‘Black’, ‘Green’, ‘Blue’}

b)

{‘Yellow’, ‘Orange’, ‘Black’, [“Blue”, “Green”, “Red”]}

c)

TypeError: update() doesn’t allow list as a argument.

43.

What will be the output of the following union operation?

a)

{10, 20, 30, 40, 50}

b)

 {20, 30}


c)

 {10, 20, 30, 40, ’10’, 50}


d)

 Error: Different types cannot be used with sets


44.

What will be the output of the following set operation?

a)

 {1, 2, 3, 4, 5}


b)

 {3}


c)

 {1, 2}



d)

 {4, 5}


45.

What will be the output of the following code?

a)

False
False

b)

True
True

c)

True
False

d)

True
False