Python Programming Questions For Fresher
Python Programming Questions For Fresher
Python Programming Questions For Fresher
a. 129
b. 8
c. 121
d. None of the above.
Correct Answer
The above code will print 129 by following the BEDMAS rule of operator precedence.
a. [2, 2, 3]
b. (2, 2, 3)
c. (1, 2, 3)
Error.
Correct Answer
Since we convert a to a tuple and then try to change its content, we will get an error since tuples
are immutable.
a. 15
b. 0
c. 20
d. None of these
Correct Answer
The above code calculates the sum of all elements in the list.
a. 0 1 2 ….. 15
b. Infinite Loop
c. 0 3 6 9 12 15
d. 0 3 6 9 12
Correct Answer
The above code prints the multiples of 3 not greater than 15, and then breaks off.
Correct Answer
The above function basically calculates the gcd of 2 numbers recursively. The gcd of 20 and 50
is 10, so the answer is A.
Correct Answer
This is a consequence of “Pass by Object Reference” in Python.
value = "Global"
func()
print(value)
a. Local
b. Global
c. None
d. Cannot be predicted
Correct Answer
We set the value of “value” as Global. To change its value from inside the function, we use the
global keyword along with “value” to change its value to local, and then print it.
a. 3 1 1 3
b. 3 1 3 1
c. 1 3 1 3
d. 1 3 3 1
Correct Answer
The above code snippet swaps 2 numbers in Python.
10. What will be the output of the following code snippet?
def thrive(n):
if n % 15 == 0:
print("thrive", end = “ ”)
elif n % 3 != 0 and n % 5 != 0:
print("neither", end = “ ”)
elif n % 3 == 0:
print("three", end = “ ”)
elif n % 5 == 0:
print("five", end = “ ”)
thrive(35)
thrive(56)
thrive(15)
thrive(39)
Correct Answer
Multiples of both 3 and 5 prints thrive. Multiples of neither 3 nor 5 prints neither. Multiples of 3
prints three and multiple of 5 prints five.
check(12)
a. Even
b. Odd
c. Error
d. None
Correct Answer
The program uses ternary operators to check if a given number is even or not.
Correct Answer
The del keyword deletes an element from a list at a given index.
Correct Answer
The filter function returns an object of type “filter”.
Correct Answer
The above code basically forms a list containing the odd numbers in the numbers list, in sorted
order.
15. What will be the output of the following code snippet?
dict1 = {'first' : 'sunday', 'second' : 'monday'}
dict2 = {1: 3, 2: 4}
dict1.update(dict2)
print(dict1
Correct Answer
The update function in python merges the contents of 2 dictionaries and stores them in the
invoking dictionary.
a. {'Hello':'World', 'First': 1}
b. {'World': 'Hello', 1: 'First'}
c. Can be both A or B
d. None of the above
Correct Answer
This is an example of dict comprehension in Python, in which we are reversing the key-value
pairs from the 1st dictionary into the second.
a. pYtHoN PrOgRaMmInG
b. Python Programming
c. python programming
d. PYTHON PROGRAMMING
Correct Answer
In this code snippet, we convert every element in odd index to lower case and every element in
even index to uppercase.
a. 20
b. 45
c. 54
d. 4,5
Correct Answer
In this code snippet, we break the given string into its 2 integer components, and then find their
product, considering them as integer types.
a. Sunday
b. Wednesday
c. Sunday Monday Tuesday Wednesday
d. None of the above.
Correct Answer
We pass a variable number of arguments into the function using *args, and then print their
value.
Correct Answer
We can pass multiple key-word arguments to a function using kwargs. Here, we print the
arguments passed to the function in this code snippet.
a. 2 3 -3 3.3
b. 3 4 -3 3
c. 2 3 -3 3
d. 2 3 -3 -3.3
Correct Answer
Option A will be the correct answer for this code snippet.
Correct Answer
The ^ operator in sets will return a set containing common of elements of its operand sets.
a. [1, 2]
b. [5, 6]
c. [1, 2, 5, 6]
d. [3, 4]
Correct Answer
Above code snippet prints the values in a, which are not present in b.
Correct Answer
Python is written in the C language.
25. What will be the result of the following expression in Python “2 ** 3 + 5 ** 2”?
a. 65536
b. 33
c. 169
d. None of these
Correct Answer
The above expression will be evaluated as 2^3 + 5^2 = 8 + 25 = 33.