wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

python basic

Total questions: 27

Worksheet time: 14mins

Name
Class
Date
1.

What is the maximum length of a Python identifier?

a)

32

b)

16

c)

128

d)

No fixed length is specified

2.

What will be the output of the following code snippet?

print(2**3 + (5 + 6)**(1 + 1))


a)

129

b)

8

c)

121

d)

None of the above.

3.

What will be the datatype of the var in the below code snippet?

var = 10 print(type(var))

var = "Hello" print(type(var))

a)

str and int

b)

int and int

c)

str and str

d)

int and str

4.

How is a code block indicated in Python?

a)

Brackets

b)

Indentation

c)

key

d)

none of the above

5.

What will be the output of the following code snippet?

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

sum = 0

for ele in a:

sum += ele

print(sum)

a)

15

b)

0

c)

20

d)

None of the above

6.

What is the correct extension for python files ?

a)

.py

b)

.pyth

c)

.python

7.

Which of the following is true about comments

a)

Comments are used by programmers to document the code

b)

# is used to create a comment in python

c)

''' can be used to create a comment in python

d)

/* */ can be used to crate a comment in python

e)

Python ignores comments.

8.

Which of the following is not a keyword?

a)

if

b)

not

c)

global

d)

swap

9.
What is the name of the environment in Python that write your programs and then test them out?
a)
Shell
b)
Window
c)
IDLE
d)
CLI
10.
What extension must you add to the end of a file when saving?
a)
.xlsx
b)
.pptx
c)
.docx
d)
.py
11.

Python is uses braces to block off code

a)

True

b)

False

12.

Is python an interpreter or compiler programming language?

a)

Compiler

b)

Interpreter

13.
Returns the remainder from division
a)
modulus
b)
exponents
c)
boolean
d)
variables
14.

x = 5


print(x > 3 and x < 10)

a)

True

b)

False

15.

How many times hi will be printed?

a)

10

b)

9

c)

Infinite times

d)

0

16.

What will be the output of the following code snippet?

count = 0 while(True):

if count % 3 == 0:

print(count, end = " ")

if(count > 15):

break

count += 1

a)

0 1 2........15

b)

infinite loop

c)

0 3 6 9 12 15

d)

0 3 6 9 12

17.

Which of the following are valid escape symbol in Python?

a)

\n

b)

\t

c)

\\

d)

All of the above

18.



(a)  

19.

What is the output if the user types "Python"?

a)
Welcome
b)
Try again!
c)
Error
d)
Enter your password
20.

What is the output?

a)

condition

b)

True

c)

Program has a syntax error.

d)

3 > 2

21.

What is the output?

a)
Hello world!
b)
Hello world
c)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
......(repeated continuously)
d)
Error
22.

What will be the output of the given code?

a)

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

b)

0,3,6,9

c)

0,3,6

d)

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

23.

Which of the following concepts is not a part of Python?

a)

pointers

b)

Loops

c)

Dynamic typing

d)

All of the above

24.

What will be the output of the following code snippet?

a = 3

b = 1

print(a, b)

a, b = b, a

print(a, b)

a)

3 1 1 3

b)

3 1 3 1

c)

1 3 1 3

d)

1 3 3 1

25.

Which of the following types of loops are not supported in Python?

a)

for

b)

while

c)

do-while

d)

none of the above

26.

Which of the following is the proper syntax to check if a particular element is present in a list?

a)

if ele in list

b)

if not ele not in list

c)

Both a and b

d)

none of the above

27.

What will be the output of the following code snippet?

example = ["Sunday", "Monday", "Tuesday", "Wednesday"]

print(example[-3:-1])

a)

['Monday' , 'Tuesday']

b)

['Monday' , 'Sunday']

c)

['Monday' , 'Wednesday']

d)

['Wednesday' , 'Tuesday']