wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

What is the first step in problem-solving?

a)

Coding the solution

b)

Defining the problem

c)

Testing the solution

d)

Debugging the code

2.

Which of the following is a correct way to start a Python program?

a)

#include

b)

BEGIN

c)

print("Hello World")

d)

echo "Hello"

3.

Which of the following is a mutable data type?

a)

Tuple

b)

List

c)

String

d)

Int

4.

What will type(3.14) return?

a)

<class 'int'>

b)

<class 'float'>

c)

<class 'str'>

d)

<class 'bool'>

5.

Which operator is used for floor division?

a)

/

b)

//

c)

%

d)

**

6.

Which function converts a string "100" to integer?

a)

int("100")

b)

str("100")

c)

float("100")

d)

bool("100")

7.

Which of the following is a syntax error?

a)

print("Hello)

b)

x = 5 + 3

c)

y = x * 2

d)

name = "Alice"

8.

Logical error is when:

a)

Program does not run

b)

Program runs but gives wrong output

c)

Program throws syntax error

d)

Program crashes

9.

Which statement is used to get user input?

a)

scan()

b)

input()

c)

read()

d)

get()

10.

Which is not a valid Python identifier?

a)

my_var

b)

var123

c)

123var

d)

_var

11.

Example of conditional statement:

a)

for

b)

if

c)

while

d)

print()

12.

What is 5 % 2?

a)

0

b)

1

c)

2.5

d)

5

13.

Which is a logical operator?

a)

+

b)

and

c)

*

d)

=

14.

Output of len("Python")?

a)

5

b)

6

c)

7

d)

8

15.

String method to convert to uppercase?

a)

upper()

b)

lower()

c)

capitalize()

d)

title()

16.

Remove whitespace from start & end of string?

a)

strip()

b)

replace()

c)

split()

d)

join()

17.

"Hello".replace("H","J") returns:

a)

"Hello"

b)

"Jello"

c)

"JelloHello"

d)

"HelloJ"

18.

Tuple method to count occurrences?

a)

append()

b)

count()

c)

remove()

d)

insert()

19.

First element of t = (1,2,3)?

a)

t[0]

b)

t[1]

c)

t.first()

d)

t.get(0)

20.

Dictionary method to get all keys?

a)

keys()

b)

append()

c)

pop(3)

d)

insert()

21.

Add new key-value to dictionary d={}?

a)

d.add("a",1)

b)

d["a"]=1

c)

d.append("a",1)

d)

d.insert("a",1)

22.

Loop to execute block fixed times?

a)

while

b)

for

c)

if

d)

elif

23.

Loop continues while condition true?

a)

for

b)

while

c)

do-while

d)

repeat

24.

list("Python") returns?

a)

"Python"

b)

['P','y','t','h','o','n']

c)

['Python']

d)

['Py','th','on']

25.

Add 10 to l=[1,2,3]?

a)

l.add(10)

b)

l.append(10)

c)

l.insert(10)

d)

l.push(10)

26.

Remove element at index from list?

a)

pop()

b)

remove()

c)

delete()

d)

discard()

27.

Immutable type?

a)

List

b)

Tuple

c)

Dictionary

d)

Set

28.

Check if key exists in dict?

a)

key in dict

b)

dict.has_key(key)

c)

key.exists()

d)

dict.contains(key)

29.

Correct if-statement syntax?

a)

if x = 5:

b)

if x == 5:

c)

if (x = 5)

d)

if x := 5

30.

Convert value to float?

a)

float()

b)

int()

c)

str()

d)

bool()

31.

Output of: x = 5 if x > 3: print("Yes") else: print("No")

a)

Yes

b)

No

c)

5

d)

Error

32.

Exponentiation operator in Python?

a)

^

b)

**

c)

*

d)

//

33.

"Python"[1:4] returns?

a)

Hel

b)

yth

c)

Pyt

d)

hon

34.

"Python".split("y") returns?

a)

['Python']

b)

['P','thon']

c)

['Py','th','on']

d)

['P','y','t','h','o','n']

35.

" ".join(['Hello','World']) returns?

a)

'HelloWorld'

b)

'Hello World'

c)

'H e l l o W o r l d'

d)

'Hello+World'

36.

Remove value x from list?

a)

l.pop(x)

b)

l.remove(x)

c)

l.del(x)

d)

l.discard(x)

37.

Add element at index 1 in list?

a)

l.add(1,10)

b)

l.insert(1,10)

c)

l.append(10,1)

d)

l.push(1,10)

38.

Remove last element in dictionary d?

a)

d.popitem()

b)

d.pop()

c)

d.remove()

d)

d.clear()

39.

Returns value of key k safely?

a)

d.get(k)

b)

d[k]

c)

d.lookup(k)

d)

d.search(k)

40.

Iterate dictionary keys?

a)

for k,v in d:

b)

for k in d:

c)

for d in k:

d)

for v in d:

41.

What is bool("")?

a)

True

b)

False

c)

Error

d)

None

42.

Output of 5==5 and 3>2?

a)

True

b)

False

c)

Error

d)

None

43.

Output of not(5>2)?

a)

True

b)

False

c)

3

d)

Error

44.

Iterates over list [1,2,3]?

a)

for x in [1,2,3]: print(x)

b)

while x in [1,2,3]: print(x)

c)

do x in [1,2,3]: print(x)

d)

loop x in [1,2,3]: print(x)

45.

t = (1,2,3); t[1] = 5 gives?

a)

(1,5,3)

b)

Error

c)

(5,2,3)

d)

(1,2,3,5)

46.

Tuple with one element?

a)

(5)

b)

(5,)

c)

[5]

d)

{5}

47.

Delete key 'a' from dictionary d={'a':1}?

a)

del d['a']

b)

d.remove('a')

c)

d.popitem('a')

d)

d.pop('b')

48.

Check if list l=[1,2] contains 2?

a)

2 in l

b)

2.exists(l)

c)

l.has(2)

d)

l.check(2)

49.

Convert integer 5 to string?

a)

str(5)

b)

int(5)

c)

float(5)

d)

bool(5)

50.

Which is true about Python dictionaries?

a)

Keys are mutable

b)

Values are immutable

c)

Keys are unique

d)

Dictionaries are ordered in Python 2