wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Quiz

Total questions: 79

Worksheet time: 53mins

Name
Class
Date
1.

is integer a number

a)

true

b)

false

2.

chose which is a floating point

a)

14

b)

15.5

3.

chose a string

a)

"tim"

b)

"tim

c)

'tim'

d)

"tim

e)

tim

4.

in python does it matter if we type ' and " together

a)

true

b)

false

5.

in python does i t matter if we right "and" this together and 'and' together

a)

true

b)

false

6.

is boolean a data type or a condition

a)

data type only

b)

data type and condition only

c)

condition only

7.

where is python used

a)

web aplications

b)

data science

c)

mobile apps

d)

GUI applications

8.

is boolean true or false

a)

true only

b)

false only

c)

true and false only

9.

Who developed Python Programming Language?

a)

a) Wick van Rossum

b)

b) Rasmus Lerdorf

c)

c) Guido van Rossum

d)

d) Niene Stom

10.

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

a)

a) .python

b)

b) .pl

c)

c) .py

d)

d) .p

11.

What will be the value of the following Python expression?

4 + 3 % 5

a)

a) 7

b)

b) 2

c)

c) 4

d)

d) 1

12.

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

a)

a) Indentation

b)

b) Key

c)

c) Brackets

d)

d) All of the mentioned

13.

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

a)

a) //

b)

b) #

c)

c) !

d)

d) /*

14.

What is the order of precedence in python?

a)

a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction

b)

b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction

c)

c) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition

d)

d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction

15.

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

a)

a) factorial()

b)

b) print()

c)

c) seed()

d)

d) sqrt()

16.

Which of the following is not a core data type in Python programming?

a)

a) Tuples

b)

b) Lists

c)

c) Class

d)

d) Dictionary

17.

To add a new element to a list we use which Python command?

a)

a) list1.addEnd(5)

b)

b) list1.addLast(5)

c)

c) list1.append(5)

d)

d) list1.add(5)

18.

What will be the output of the following Python statement?

>>>"abcd"[2:]

a)

a) a

b)

b) ab

c)

c) cd

d)

d) dc

19.

What will be the output of the following Python code?

>>> str1 = 'hello'

>>> str2 = ','

>>> str3 = 'world'

>>> str1[-1:]

a)

a) olleh

b)

b) hello

c)

c) h

d)

d) o

20.

What will be the output of the following Python code?

>>>str1="helloworld"

>>>str1[::-1]

a)

a) dlrowolleh

b)

b) hello

c)

c) world

d)

d) helloworld

21.

What will be the output of the “hello” +1+2+3?

a)

a) hello123

b)

b) hello

c)

c) Error

d)

d) hello6

22.

Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?

a)

a) 5

b)

b) 4

c)

c) None

d)

d) Error

23.

Suppose list1 is [2445,133,12454,123], what is max(list1)?

a)

a) 2445

b)

b) 133

c)

c) 12454

d)

d) 123

24.

Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?

a)

a) [2, 33, 222, 14]

b)

b) Error

c)

c) 25

d)

d) [25, 14, 222, 33, 2]

25.

If a=(1,2,3,4), a[1:-1] is _________

a)

a) Error, tuple slicing doesn’t exist

b)

b) [2,3]

c)

c) (2,3,4)

d)

d) (2,3)

26.

Which of the following statements create a dictionary?

a)

a) d = {}

b)

b) d = {“john”:40, “peter”:45}

c)

c) d = {40:”john”, 45:”peter”}

d)

d) All of the mentioned

27.

What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}

d["john"]

a)

a) 40

b)

b) 45

c)

c) “john”

d)

d) “peter”

28.

What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}

b={4:"D",5:"E"}

a.update(b)

print(a)

a)

a) {1: ‘A’, 2: ‘B’, 3: ‘C’}

b)

b) Method update() doesn’t exist for dictionaries

c)

c) {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}

d)

d) {4: ‘D’, 5: ‘E’}

29.

Python accepts single ('), double (") and triple (''' or """) quotes to denote strings. Which of the following is NOT acceptable Python syntax?

a)

print('Hello World')

b)

print("Hello World")

c)

print('Hello World")

d)

print(""'Hello World'"")

30.

What is printed by the following statement?

print("P" not in "APCSP")

a)

True

b)

False

c)

Error

31.

What is printed by the following statement?

print("A" in "APCSP")

a)

True

b)

False

c)

Error

32.

Evaluate the following expression:

"dog" < "Dog"

a)

They are the same word

b)

True

c)

False

33.

For strings, the + operator represents

a)

Concatenation

b)

Addition

c)

Appending

d)

Recantation

34.

data = "No Way!" The expression len(data) evaluates to:

a)

7

b)

9

c)

8

d)

6

35.

Which operator returns True if target string is somewhere in the search string; otherwise it returns False.

a)

==

b)

!=

c)

in

d)

is

36.

What syntax can you use to insert a line break between strings so that they appear over multiple lines?

a)

\l

b)

/

c)

\\n

d)

\n

37.

Which is the most appropriate data type for: "13th December"

a)

Float

b)

Boolean

c)

Integer

d)

String

38.

What will the output be from the following code?

print("Hello world!" * 2)

a)

TypeError

b)

Hello world world!

c)

Hello world!Hello world!

d)

Hello world! * 2

39.

What will the output be from the following code?

print("Hello world!\nHello world!")

a)

Hello world! Hello world!

b)

Hello world!

Hello world!

c)

SyntaxError

d)

Hello world!

40.

What will the output be from the following code?

print("3+4")

a)

7

b)

34

c)

3+4

d)

SyntaxError

41.

print("12"*3)

What would this print?

a)

121212

b)

36

c)

24

d)

12*3

42.

What will the output be from the following code?

print("Hello world!")

a)

SyntaxError

b)

Hello world!

c)

"Hello world!"

d)

print(Hello world!)

43.

The program above

a)

prints all the odd numbers between 1 and 20

b)

prints all even numbers between 1 and 20

c)

print all the odd numbers between 1 and 21

d)

prints all the even numbers between 1 and 21

44.

The equivalent of the above for loop using the while syntax would be

a)
b)
c)
d)
45.

The above program prints

a)

Numbers 1 to 10 in reverse order

b)

Numbers 1 to 11 in reverse order

c)

Numbers 1 to 10

d)

Numbers 1 to 11

46.

The program above prints

a)

Numbers between 1 and 100 that are multiples of 5

b)

Numbers between 1 and 100

c)

Numbers between 1 and 100 divisible by 5

d)

Numbers between 1 and 101 that are multiples of 5

47.

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

a)

not divisible by 5

b)

divisible by 5

48.

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

49.

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

50.

The program above prints each number between 1 and 10

a)

as many times as the number itself

b)

10 times

c)

11 times

51.

The program above prints each number between 1 and 10

a)

as many times as the number itself

b)

10 times

c)

11 times

52.

How many times will 1 be printed

a)

3

b)

4

c)

5

d)

6

53.

for i in 100 :

print ( i )

a)

Syntax error

b)

prints numbers 0 to 100

c)

prints numbers 1 to 100

d)

prints numbers 0 to 99

e)

prints numbers 1 to 99

54.

What is the output of the program above

a)

10

b)

15

c)

18

d)

17

e)

16

55.

A while loop equivalent of the for loop above is

a)
b)
c)
d)
56.

What is the value of the variable sum after the code above executes

a)

54

b)

44

c)

64

d)

34

e)

74

57.

What does this program print

a)

2 + 2 = 4

4 + 4 = 8

8 + 8 = 16

16 + 16 = 32

32 + 32 = 64

b)

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

c)

2 + 2 = 4

2 + 4 = 6

2 + 6 = 8

2 + 8 = 10

2 + 10 = 12

d)

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

e)

2 + 2 = 4

2 + 4 = 6

2 + 6 = 8

2 + 8 = 10

58.

__________ keyword is used for creating a function in Python.

a)

define

b)

fun

c)

def

d)

function

59.

What is the output of the given code?

a)

10 20 10

b)

10

c)

20

d)

10 20

60.

What is the output of the given code?

a)

10 20 10 20

b)

10 20 10

c)

10 20 20

d)

Error

61.

Python supports variable number of parameters.

a)

True

b)

False

62.

Function header in Python contains _________________.

a)

function name

b)

list of parameters

c)

return type

d)

all the above

e)

Only A & B

63.

The default return value of any function in Python is _______________.

a)

null

b)

0

c)

None

d)

Garbage value

64.

__________ is the built-in function to know the type of a variable or function.

a)

id()

b)

type()

c)

data_type()

d)

none of the above

65.

___________ are the arguments passed to a function in correct positional order.

a)

Keyword arguments

b)

Default arguments

c)

Variable-length arguments

d)

Required arguments

e)

none of the above

66.

times is ________________ type of argument.

a)

default arguments

b)

keyword arguments

c)

positional arguments

d)

arbitrary positional arguments

e)

arbitrary keyword arguments

67.

Select the advantages of functions

a)

Modular programming

b)

Code re-usability

c)

Improving clarity of the code

d)

All the above

68.

Which python operator means 'less than or equal to'?

a)

>=

b)

>

c)

<

d)

<=

69.

What is the value of the expression 100 / 25?

a)

4

b)

4.0

c)

"4.0"

d)

'4.0'

70.

What is the output of the following code :


print 9//2

a)

4.5

b)

4.0

c)

4

d)

3

71.

Which one of these is floor division?

a)

/

b)

//

c)

%

d)

None of the mentioned

72.

What is the answer of this expression, 22 % 3 is?

a)

7

b)

1

c)

0

d)

5

73.

x = 4.5

y = 2

print(x//y)

a)

2.0

b)

2

c)

9

d)

9.0

74.

x = 5


print(x > 3 and x < 10)

a)

True

b)

False

75.

x = 8


print(x > 3 or x < 20)

a)

True

b)

False

76.

x = 5

y = 3


print(x == y)

a)

True

b)

False

77.

x = 10

y = 10


print(x != y)

a)

True

b)

False

78.

x = 5


x%=3


print(x)

a)

2

b)

2.0

c)

3

d)

3.0

79.

print(not (0<1))

a)

TRUE

b)

FALSE

c)

TYPE ERROR