wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python-Loops-Iterables

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

Which of the following is not an iterable?

a)

List

b)

Dict

c)

String

d)

int

2.

Which of the Following is a mutable Data Type?

a)

List

b)

Tuple

3.

Which Arithematic Operator Cannot be used for Strings

a)

' + ' operator

b)

' - ' operator

c)

' * ' operator

d)

All the above.

4.

What will be the Output of the Code

(a)  

5.

Which of the following functions is a built-in function in python?

a)

seed

b)

print

c)

sqrt

d)

factorial

6.

What will be the output of the following Python function?

sum(2,4,6)

sum([1,2,3])

a)

Error

6

b)

12

Error

c)

12

6

d)

Error

Error

7.

How do you insert comments in python

a)

#This is a comment

b)

//This is a comment

c)

/*This is a comment*/

d)

<!This is a comment>

8.

Which one is NOT a legal variable name?

a)

VARNAME

b)

_var_name_

c)

var-name

d)

VarName

9.

What is the correct way to create a function?

a)

def myfunction():

b)

create myfunction():

c)

function myfunction():

10.

Which collection is ordered, changeable, and allows duplicate members?

a)

List

b)

Set

c)

Tuple

d)

Dictionary

11.

Which collection does not allow duplicate members?

a)

Set

b)

Tuple

c)

List

12.

What is the output for −

'Hello World' [100:200]?

a)

Index Error

b)

"Hello World"

c)

Syntax Error

d)

""

13.

Which among them is incorrect for set S={100,101,102,103}

a)

len(S)

b)

sum(S)

c)

print(S[3])

d)

max(S)

14.

st=”Cadbury Dairy Milk”

x=st.split(‘a’)

print(len(x))

What is the output of the above code?

a)

3

b)

6

c)

7

d)

9

15.

Which of the following sorts the elements of tuple?

ex: tup = (6,4,8)

a)

sort(tup)

b)

tup.sort()

c)

sorted(tup)

d)

tup.sorted()

16.

Which of the following is used to create an empty set?

a)

{}

b)

[]

c)

()

d)

set()

17.

If return statement is not used inside the function, the function will return:

a)

None Object

b)

An arbitrary int

c)

Error

d)

Function must return somethingd

18.
print("12"*3)
What would this print?
a)
36
b)
121212
c)
24
d)
12*3
19.

To remove the spaces present at start and end of the string, you can use

a)

split()

b)

len()

c)

strip()

d)

remove()

20.

The code above prints all numbers between 1 and 30 that are

a)

not divisible by 5

b)

divisible by 5

21.

The program above prints the sum of

a)

all odd numbers less than 100

b)

all even numbers less than 100

c)

all numbers less than 100

22.

The program above prints the sum of all the numbers between 0 and 101 that are

a)

alternate odd numbers

b)

alternate even numbers

c)

alternate numbers

23.

The program above prints each number between 1 and 10

a)

as many times as the number itself

b)

10 times

c)

11 times

24.

How many times will 1 be printed

a)

3

b)

4

c)

5

d)

6

25.
What will the output be from the following code?
print("3+4")
a)
7
b)
3+4
c)
34
d)
SyntaxError