wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

Which of the following is the correct extension of the Python file?

a)

.python

b)

.pl

c)

.py

d)

.p

2.

Is Python code compiled or interpreted?

a)

Python code is both compiled and interpreted

b)

Python code is neither compiled nor interpreted

c)

Python code is only compiled

d)

Python code is only interpreted

3.

What will be the value of the following Python expression?

print(4 + 3 % 5)

a)

7

b)

2

c)

4

d)

1

4.

Which of the following is used to define a block of code in Python language?

a)

Indentation

b)

Key

c)

Brackets

d)

All of the mentioned

5.

Which of the following character is used to give single-line comments in Python?

a)

//

b)

#

c)

!

d)

/*

6.

Which of the following is true for variable names in Python?

a)

underscore and ampersand are the only two special characters allowed

b)

unlimited length

c)

all private members must have leading and trailing underscores

d)

none of the mentioned

7.

What will be the output of the following Python statement?

print("a"+"bc")

a)

bc

b)

abc

c)

a

d)

bca

8.

What are arithmetic operators in Python?

a)

*

b)

-

c)

+

d)

All

9.

What is the average value of the following Python code snippet?

grade1 = 80

grade2 = 90

average = (grade1 + grade2) / 2

print(average)

a)

85.0

b)

85.1

c)

95.0

d)

95.1

10.

What is a correct syntax to output "Hello World" in Python?

a)

print("Hello World")

b)

p("Hello World")

c)

echo("Hello World")

d)

echo "Hello World"

11.

Which one is NOT a legal variable name?

a)

Myvar

b)

my_var

c)

my-var

d)

_myvar

12.

How do you create a variable with the numeric value 5?


a)

x=5

b)

x=int(5)

c)

Both a & b

d)

none of the above

13.

What is the correct syntax to output the type of a variable or object in Python?


a)

print(typeOf(x))

b)

print(type(x))

c)

print(typeof(x))

d)

print(typeof x)

14.

Which operator can be used to compare two values?

a)

=

b)

==

c)

<>

d)

><

15.

How do you start writing an if statement in Python?


a)

if x>y then:

b)

if (x>y)

c)

if x>y :

d)

None of the above

16.

What does the following expression return?

not (True and False)

a)

True

b)

False

c)

Error

d)

None

17.

What will be printed by the following code?

x = 5

x += 3

print(x)

a)

5

b)

3

c)

8

d)

15

18.

What does the following expression return in Python 3?

5 / 2

a)

2

b)

2.5

c)

2.0

d)

Error

19.

What does the += operator do?

a)

Assigns a value

b)

Adds and reassigns

c)

Compares values

d)

Increments without assignment

20.

What is the result of 5 ^ 3? (bitwise XOR)

a)

6

b)

7

c)

2

d)

1

21.

What is 5 // 2 in Python 3?

a)

0

b)

1

c)

2

d)

3

22.

What is the result of:

True and False

a)

True

b)

False

c)

Error

d)

None

23.

What is the result of 2 & 4 | 1?

a)

1

b)

0

c)

5

d)

3

24.

What is the binary number of 5?

a)

111

b)

001

c)

101

d)

011

25.

what is the decimal form of binary number 1010?

a)

7

b)

8

c)

10

d)

5