wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Quiz

Total questions: 45

Worksheet time: 23mins

Name
Class
Date
1.

Which statement is incorrect

a)

a=!b

b)

a!=b

c)

a=[1,2,3]

d)

B=(9,6,5)

2.

Output? :

a = "You're Pretty"

Print(a)

a)

You're Pretty

b)

"You're Pretty"

c)

a

d)

NameError: name 'Print' is not defined

3.

What is the output for the below program:

A="Hyperboloid"

print(len("A")

a)

11

b)

911

c)

12

d)

1

4.

What does my_list.append(5) do?

a)

Removes the last element from the list.

b)

Creates a new list with only the number 5.

c)

Appends the number 5 to the end of the list.

d)

Adds 5 to the beginning of the list.

5.

Used to define a function:

a)

Def

b)

def

c)

define

d)

Define

6.

What is the output for the below program:

for i in range(10<11):

print(i)

a)

10

b)

11

c)

0

d)

Error: logical operators cannot be used inside range()

7.

a)

[1,2,3,4,5,6,7,8,9,10]

b)

1,2,3,4,5,6,7,8,9,10

c)

[0,1,2,3,4,5,6,7,8,9]

d)

0,1,2,3,4,5,6,7,8,9

8.

Output?

a)

Error

b)

[1, 2, 3, [4], [5]]

c)

[1, 2, 3, 4, 5]

d)

[1, 2, 3, [4, 5]]

9.

What is the output for the program?

a)

ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

b)

Error:False can't be used inside the while loop

c)

Red

d)

Red

Red

Red

Red

Red

Red

10.

Output?

a)

Positive

b)

Negative

c)

Zero

d)

Positive Zero

11.

Can you modify the elements of a tuple after it has been created?

a)

Yes

b)

No

12.

What is the output for the program?

a)

1

2

3

4

b)

1

3

5

c)

1

3

d)

Error:Boolen values can't be used inside range()

13.

Output?

a)

8

b)

16

c)

Indentation Error

d)

Runtime Error

14.

How can you reverse the order of characters in the string "Hello"?

a)

"Hello".invert()

b)

reverse("Hello")

c)

"Hello".reverse()

d)

"Hello"[::-1]

15.

What is the output for the program?

a)

1

b)

1.line()

c)

1.0

d)

Attribute Error

16.

What is the output of the expression : 3*1**3

a)

27

b)

9

c)

3

d)

1

17.

Which of these is not a core data type?

a)

Lists

b)

Dictionary

c)

Tuples

d)

Class

18.

print(input("Enter a string")[::-1])

a)

Reverses the given string to the input

b)

Error : input() cannot be used inside print ()

19.

What will be the output for the below program:

print(100**1.5)

a)

3.162277

b)

100.0

c)

1000.0

d)

1.5

20.

Output?

a)

Error

b)

[1,2,3,4,5]

c)

[1,2,3,4,5,6]

d)

None of these

21.

What will be the output for the below program?

print(8**1**98)

a)

1

b)

31828687130226345097944463881396533766429193651030253916189694521162207808802136034115584

c)

98

d)

8

22.

What is the primary advantage of using a tuple over a list in certain situations?

a)

Lists have better performance.

b)

Lists are immutable.

c)

Tuples can have more elements

d)

Tuples are more memory-efficient.

23.

Output?

a)

[2,3,4,5]

b)

[3,4,5]

c)

[4,5]

d)

Error : negative index cannot be used as start value

24.

What is the result of the following operation?

a)

(5, 7, 9)

b)

[(1, 2, 3), (4, 5, 6)]

c)

(1, 2, 3, 4, 5, 6)

d)

Error: Tuple cannot be modified as Tuple is immutable

25.

What is Python?

a)

A compiled programming language.

b)

A database management system.

c)

A markup language.

d)

An interpreted scripting language

26.

What is the output for the program?

a)

can't divisible by 4

b)

divisible by 4

c)

Can't divisible by 4

d)

Error

27.

In Python, which of the following is a valid variable name?

a)

2numbers

b)

_myVar

c)

my-var

d)

first name

28.

What is the purpose of the break statement in a loop?

a)

To continue to the next iteration

b)

To skip the current iteration.

c)

To end the entire program.

d)

To exit the loop prematurely.

29.

What is a function in Python?

a)

A built-in module.

b)

A reusable block of code.

c)

A data type.

d)

A reserved keyword.

30.

Which mode is used to open a file for writing in Python?

a)

'o'

b)

'w'

c)

'r'

d)

'x'

31.

What is the difference between a list and a tuple in Python?

a)

Lists are mutable, tuples are immutable

b)

Lists are ordered, tuples are unordered

c)

Lists can have different data types, tuples cannot

d)

All the above

32.

What is a module in Python?

a)

A collection of functions.

b)

A file containing Python code that defines variables and functions.

c)

A built-in data type.

d)

A loop structure.

33.

What is the difference between range(5) and range(1, 6)?

a)

No difference

b)

range(5) includes 5, range(1, 6) does not

c)

range(1, 6) includes 5, range(5) does not

d)

In range(1,6) the range will conclude with 6 whereas in range(5) the range will conclude with 5

34.

How do you create an infinite loop using while?

a)

While True:

b)

while true:

c)

While true:

d)

while True:

35.

What is the purpose of the range() function in a for loop?

a)

Defines the loop condition

b)

Generates a sequence of numbers

c)

Specifies the loop iteration step

d)

Runs the loop infinitely

36.

Which statement is incorrect?

a)

X=Tuple(input("Enter Tuple"))

b)

X=List(input("Enter List"))

c)

X=str(input("Enter a string"))

d)

X=int(input("Enter a number"))

37.

Which statement is incorrect?

a)

print("g"[::-1])

b)

print(' ,"&£@(-__-):')

c)

if h<6:

d)

if a in x

38.

Can a compiler have the ability to run this code:

for i in range(10000,0,1):

a)

Yes

b)

No

c)

Impossible for low end compilers

39.

What is the output for the program?

a)

(2,4,5,6,7,9)

b)

Error : Tuple cannot be modified using list operatoions

c)

[(2,4,6,7),9]

d)

[2,4,5,6,7,9]

40.

What is the main advantage of using lambda functions in Python?

a)

They provide a concise way to create small anonymous functions.

b)

They can be used only for mathematical operations.

c)

They are more memory-efficient.

d)

They allow for multi-line code blocks.

41.

What is an iterator in Python?

a)

A special type of list.

b)

An object that can be iterated (looped) over.

c)

A function that returns a sequence of numbers.

d)

A built-in data type.

42.

In Python, how does a variable declared inside a function differ from one declared outside a function?

a)

Variables inside a function can only be accessed from other functions.

b)

Variables inside a function are global by default.

c)

There is no difference.

d)

Variables inside a function have local scope.

43.

What is recursion in Python?

a)

A method for defining class attributes.

b)

A loop structure.

c)

A way to handle exceptions.

d)

A function that calls itself.

44.

What will be the output for the below program:

print("Hello*3")

a)

HelloHelloHello

b)

HelloHelloHellO

c)

Error

d)

Hello*3

45.

What character is used to indicate a single-line comment in Python?

a)

//

b)

/* */

c)

--

d)

#