NEW
Font size
WorksheetsPython Programming MCQs
Total questions: 50
Worksheet time: 25mins
Who developed Python Programming Language?
Wick van Rossum
Rasmus Lerdorf
Guido van Rossum
Niene Stom
Which type of Programming does Python support?
object-oriented programming
structured programming
functional programming
all of the mentioned
Is Python case sensitive when dealing with identifiers?
no
yes
machine dependent
none of the mentioned
Which of the following is the correct extension of the Python file?
.python
.pl
.py
.p
Is Python code compiled or interpreted?
Python code is both compiled and interpreted
Python code is neither compiled nor interpreted
Python code is only compiled
Python code is only interpreted
All keywords in Python are in ________
Capitalized
lower case
UPPER CASE
None of the mentioned
Which of the following is used to define a block of code in Python language?
Indentation
Key
Brackets
All of the mentioned
Which of the following character is used to give single-line comments in Python?
//
#
!
/*
What will be the output of the following Python code?
1
2
no output
error
What will be the output of the following Python code?
1 2 3
error
1 2
none of the mentioned
What will be the output of the following Python code snippet if x=1?
4
2
1
8
Which of the following is true for variable names in Python?
underscore and ampersand are the only two special characters allowed
unlimited length
all private members must have leading and trailing underscores
none of the mentioned
What are the values of the following Python expressions?
512, 64, 512
512, 512, 512
64, 512, 64
64, 64, 64
Which of the following is the use of id() function in python?
Every object doesn't have a unique id
Id returns the identity of the object
All of the mentioned
None of the mentioned
The following python program can work with ____ parameters.
any number of
0
Which of the following is not a core data type in Python programming?
Tuples
Lists
Class
Dictionary
What is the order of namespaces in which Python looks for an identifier?
Python first searches the built-in namespace, then the global namespace and finally the local namespace
Python first searches the built-in namespace, then the local namespace and finally the global namespace
Python first searches the local namespace, then the global namespace and finally the built-in namespace
Python first searches the global namespace, then the local namespace and finally the built-in namespace
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)
12
224
None
Error
print(id(q) == foo(q))
Error
None
False
True
What arithmetic operators cannot be used with strings in Python?
*
-
+
All of the mentioned
What will be the output of the following Python code? print("abc. DEF".capitalize())
Abc. def
abc. def
Abc. Def
ABC. DEF
Which of the following statements is used to create an empty set in Python?
()
[]
{}
set()
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)
[1, 3, 5, 7, 8]
[1, 7, 8]
[1, 2, 4, 7, 8]
error
To add a new element to a list we use which Python command?
list1.addEnd(5)
list1.addLast(5)
list1.append(5)
list1.add(5)
What will be the output of the following Python code? print("*", "abcde".center(6, "*"), "*", sep="")
* abcde *
*abcde *
* abcde*
* abcde *
What will be the output of the following Python code? 1. >>> list1 = [1, 3] 2. >>> list2 = list1 3. >>> list1[0] = 4 4. >>> print(list2)
[1, 4]
[1, 3, 4]
[4, 3]
[1, 3]
Which one of the following is the use of function in python?
Functions don’t provide better modularity for your application
you can’t also create your own functions
Functions are reusable pieces of programs
All of the mentioned
Which of the following Python statements will result in the output: 6? A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
A[2][1]
A[1][2]
A[3][2]
A[2][3]
What is the maximum possible length of an identifier in Python?
79 characters
31 characters
63 characters
none of the mentioned
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)
error
0 1 2 0
0 1 2
none of the mentioned
What will be the output of the following Python code? x = 'abcd' for i in range(len(x)): print(i)
error
1 2 3 4
a b c d
0 1 2 3
What are the two main types of functions in Python?
System function
Custom function
Built-in function & User defined function
User function
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))
5
8
2
1
Which of the following is a Python tuple?
{1, 2, 3}
{}
[1, 2, 3]
(1, 2, 3)
What will be the output of the following Python code snippet? z = set('abc$de') 'a' in z
Error
True
False
No output
What will be the output of the following Python expression? round(4.576)
4
4.6
5
4.5
Which of the following is the use of id() function in python?
Every object in Python doesn’t have a unique id
In Python Id function returns the identity of the object
None of the mentioned
All of the mentioned
What will be the output of the following Python code? x = [[0], [1]] print((''.join(list(map(str, x))),))
01
[0] [1]
('01')
('[0] [1]',)
What will be the output of the following Python code? def foo(): try: return 1 finally: return 2 k = foo() print(k)
error, there is more than one return statement in a single try-finally block
3
2
1
Given a function that does not return any value, What value is thrown by default when executed in shell.
int
bool
void
None
What will be the output of the following Python code? 1. >>> str = "hello" 2. >>> str[:2]
he
'he'
['h', 'e']
error
>>>
he
lo
olleh
hello
What is the return type of function id?
int
float
bool
dict
What data type is the object below? L = [1, 23, 'hello', 1]
list
dictionary
array
tuple
In order to store values in terms of key and value we use what core data type.
list
tuple
class
dictionary
Which of the following results in a SyntaxError?
"’Once upon a time…’, she said.’
"He said, ‘Yes!’"
‘3’
"’That’s okay’"
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
print("tom\ndick\nharry")
print('tomdickharry')
print('tom\ndick\nharry')
print('tomdickharry')
What is the average value of the following Python code snippet? >>> grade1 = 80 >>> grade2 = 90 >>> average = (grade1 + grade2) / 2
85.0
85.1
95.0
95.1
Select all options that print: hello-how-are-you
print('hello-', 'how-', 'are-', 'you')
print('hello', 'how', 'are', 'you')
print('hello-' + 'how-are-you')
print('hello' + '-' + 'how' + '-' + 'are' + '-' + 'you')
What will be the output of the following Python code snippet if x=1? x<<2
8
1
2
4
