Quiz on Python Language

1) Which keyword is used for function declaration in Python?

a) func

b) define

c) def

d) function

Answer: c) def

2) What is the output of '2 + 3 * 4' in Python?

a) 20

b) 14

c) 18

d) 10

Answer: b) 14

3) What data type is (5,)?

a) List

b) Tuple

c) Dictionary

d) Set

Answer: b) Tuple

4) What does the 'len()' function do in Python?

a) Returns the length of a string

b) Returns the largest number

c) Returns the smallest number

d) Returns the length of a list or tuple

Answer: d) Returns the length of a list or tuple

5) What will be the output of 'print(type(5.0))' in Python?

a) float

b) int

c) str

d) bool

Answer: a) float

6) Which method is used to remove an element from a list?

a) delete()

b) remove()

c) pop()

d) erase()

Answer: b) remove()

7) What will 'bool("False")' return in Python?

a) True

b) False

c) Error

d) Depends on context

Answer: a) True

8) What is the purpose of the 'break' statement in Python?

a) Skips the current iteration in a loop and continues with the next iteration

b) Terminates the loop and transfers control to the next statement after the loop

c) Terminates the program

d) Raises an exception

Answer: b) Terminates the loop and transfers control to the next statement after the loop

9) What does the 'range()' function in Python return?

a) List

b) Tuple

c) Dictionary

d) Iterator

Answer: d) Iterator

10) What is the symbol used for 'floor division' in Python?

a) //

b) %

c) **

d) /

Answer: a) //

11) What is the output of 'bool(0)' in Python?

a) True

b) False

c) Error

d) 0

Answer: b) False

12) Which module in Python supports regular expressions?

a) re

b) regex

c) pyregex

d) regexpy

Answer: a) re

13) What is the correct way to open a file 'file.txt' in Python?

a) open('file.txt', 'r')

b) read('file.txt')

c) open_file('file.txt')

d) file_open('file.txt')

Answer: a) open('file.txt', 'r')

14) Which method is used to add an element to the end of a list in Python?

a) add()

b) extend()

c) append()

d) insert()

Answer: c) append()

15) What does the 'ord()' function in Python do?

a) Returns the ordinal value of a character

b) Rounds off a decimal number

c) Returns the order of a list element

d) Opens a file for reading

Answer: a) Returns the ordinal value of a character

16) Which of the following is a correct way to check if a key exists in a dictionary in Python?

a) keyExists(key)

b) key in dictionary

c) exists(key)

d) isKeyPresent(key)

Answer: b) key in dictionary

17) What is the purpose of the 'pass' statement in Python?

a) Terminates the program

b) Skips current iteration in a loop

c) Allows the program to continue without any action

d) Raises an exception

Answer: c) Allows the program tocontinue without any action

Explore Categories

JAVA

PYTHON

JAVASCRIPT

PHP

REACT

BOOTSTRAP

CSS

C & C++

HOMEPAGE