wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming MCQs

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

Who developed Python Programming Language?

a)

Wick van Rossum

b)

Rasmus Lerdorf

c)

Guido van Rossum

d)

Niene Stom

2.

Which type of Programming does Python support?

a)

object-oriented programming

b)

structured programming

c)

functional programming

d)

all of the mentioned

3.

Is Python case sensitive when dealing with identifiers?

a)

no

b)

yes

c)

machine dependent

d)

none of the mentioned

4.

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

a)

.python

b)

.pl

c)

.py

d)

.p

5.

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

6.

All keywords in Python are in ________

a)

Capitalized

b)

lower case

c)

UPPER CASE

d)

None of the mentioned

7.

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

8.

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

a)

//

b)

#

c)

!

d)

/*

9.

What will be the output of the following Python code?

a)

1

b)

2

c)

no output

d)

error

10.

What will be the output of the following Python code?

a)

1 2 3

b)

error

c)

1 2

d)

none of the mentioned

11.

What will be the output of the following Python code snippet if x=1?

a)

4

b)

2

c)

1

d)

8

12.

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

13.

What are the values of the following Python expressions?

a)

512, 64, 512

b)

512, 512, 512

c)

64, 512, 64

d)

64, 64, 64

14.

Which of the following is the use of id() function in python?

a)

Every object doesn't have a unique id

b)

Id returns the identity of the object

c)

All of the mentioned

d)

None of the mentioned

15.

The following python program can work with ____ parameters.

a)

any number of

b)

0

16.

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

a)

Tuples

b)

Lists

c)

Class

d)

Dictionary

17.

What is the order of namespaces in which Python looks for an identifier?

a)

Python first searches the built-in namespace, then the global namespace and finally the local namespace

b)

Python first searches the built-in namespace, then the local namespace and finally the global namespace

c)

Python first searches the local namespace, then the global namespace and finally the built-in namespace

d)

Python first searches the global namespace, then the local namespace and finally the built-in namespace

18.

What will be the output of the following Python code? 1. class tester: 2. def __init__(self, id): 3. self.id = str(id) 4. id = "224" 5. >>> temp = tester(12) 6. >>> print(temp.id)

a)

12

b)

224

c)

None

d)

Error

19.

print(id(q) == foo(q))

a)

Error

b)

None

c)

False

d)

True

20.

What arithmetic operators cannot be used with strings in Python?

a)

*

b)

-

c)

+

d)

All of the mentioned

21.

What will be the output of the following Python code? print("abc. DEF".capitalize())

a)

Abc. def

b)

abc. def

c)

Abc. Def

d)

ABC. DEF

22.

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

a)

()

b)

[]

c)

{}

d)

set()

23.

What will be the value of 'result' in following Python program? list1 = [1,2,3,4] list2 = [2,4,5,6] list3 = [2,6,7,8] result = list() result.extend(i for i in list1 if i not in (list2+list3) and i not in result) result.extend(i for i in list2 if i not in (list1+list3) and i not in result) result.extend(i for i in list3 if i not in (list1+list2) and i not in result)

a)

[1, 3, 5, 7, 8]

b)

[1, 7, 8]

c)

[1, 2, 4, 7, 8]

d)

error

24.

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

a)

list1.addEnd(5)

b)

list1.addLast(5)

c)

list1.append(5)

d)

list1.add(5)

25.

What will be the output of the following Python code? print("*", "abcde".center(6, "*"), "*", sep="")

a)

* abcde *

b)

*abcde *

c)

* abcde*

d)

* abcde *

26.

What will be the output of the following Python code? 1. >>> list1 = [1, 3] 2. >>> list2 = list1 3. >>> list1[0] = 4 4. >>> print(list2)

a)

[1, 4]

b)

[1, 3, 4]

c)

[4, 3]

d)

[1, 3]

27.

Which one of the following is the use of function in python?

a)

Functions don’t provide better modularity for your application

b)

you can’t also create your own functions

c)

Functions are reusable pieces of programs

d)

All of the mentioned

28.

Which of the following Python statements will result in the output: 6? A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

a)

A[2][1]

b)

A[1][2]

c)

A[3][2]

d)

A[2][3]

29.

What is the maximum possible length of an identifier in Python?

a)

79 characters

b)

31 characters

c)

63 characters

d)

none of the mentioned

30.

What will be the output of the following Python program? i = 0 while i < 5: print(i) i += 1 if i == 3: break else: print(0)

a)

error

b)

0 1 2 0

c)

0 1 2

d)

none of the mentioned

31.

What will be the output of the following Python code? x = 'abcd' for i in range(len(x)): print(i)

a)

error

b)

1 2 3 4

c)

a b c d

d)

0 1 2 3

32.

What are the two main types of functions in Python?

a)

System function

b)

Custom function

c)

Built-in function & User defined function

d)

User function

33.

What will be the output of the following Python program? 1. def addItem(listParam): 2. listParam += [1] 3. 4. mylist = [1, 2, 3, 4] 5. addItem(mylist) 6. print(len(mylist))

a)

5

b)

8

c)

2

d)

1

34.

Which of the following is a Python tuple?

a)

{1, 2, 3}

b)

{}

c)

[1, 2, 3]

d)

(1, 2, 3)

35.

What will be the output of the following Python code snippet? z = set('abc$de') 'a' in z

a)

Error

b)

True

c)

False

d)

No output

36.

What will be the output of the following Python expression? round(4.576)

a)

4

b)

4.6

c)

5

d)

4.5

37.

Which of the following is the use of id() function in python?

a)

Every object in Python doesn’t have a unique id

b)

In Python Id function returns the identity of the object

c)

None of the mentioned

d)

All of the mentioned

38.

What will be the output of the following Python code? x = [[0], [1]] print((''.join(list(map(str, x))),))

a)

01

b)

[0] [1]

c)

('01')

d)

('[0] [1]',)

39.

What will be the output of the following Python code? def foo(): try: return 1 finally: return 2 k = foo() print(k)

a)

error, there is more than one return statement in a single try-finally block

b)

3

c)

2

d)

1

40.

Given a function that does not return any value, What value is thrown by default when executed in shell.

a)

int

b)

bool

c)

void

d)

None

41.

What will be the output of the following Python code? 1. >>> str = "hello" 2. >>> str[:2]

a)

he

b)

'he'

c)

['h', 'e']

d)

error

42.

>>>

a)

he

b)

lo

c)

olleh

d)

hello

43.

What is the return type of function id?

a)

int

b)

float

c)

bool

d)

dict

44.

What data type is the object below? L = [1, 23, 'hello', 1]

a)

list

b)

dictionary

c)

array

d)

tuple

45.

In order to store values in terms of key and value we use what core data type.

a)

list

b)

tuple

c)

class

d)

dictionary

46.

Which of the following results in a SyntaxError?

a)

"’Once upon a time…’, she said.’

b)

"He said, ‘Yes!’"

c)

‘3’

d)

"’That’s okay’"

47.

The following is displayed by a print function call. Select all of the function calls that result in this output: 1. tom 2. dick 3. harry

a)

print("tom\ndick\nharry")

b)

print('tomdickharry')

c)

print('tom\ndick\nharry')

d)

print('tomdickharry')

48.

What is the average value of the following Python code snippet? >>> grade1 = 80 >>> grade2 = 90 >>> average = (grade1 + grade2) / 2

a)

85.0

b)

85.1

c)

95.0

d)

95.1

49.

Select all options that print: hello-how-are-you

a)

print('hello-', 'how-', 'are-', 'you')

b)

print('hello', 'how', 'are', 'you')

c)

print('hello-' + 'how-are-you')

d)

print('hello' + '-' + 'how' + '-' + 'are' + '-' + 'you')

50.

What will be the output of the following Python code snippet if x=1? x<<2

a)

8

b)

1

c)

2

d)

4