MCQ : Functions in python For NIELIT O Level Exam

Functions in python For NIELIT O Level Exam

00:00:00

What will be the output of the following Python code?

print('*', "abcde".center(6), '*', sep='')

Option A. * abcde *
Option B. * abcde *
Option C. *abcde *
Option D. * abcde*
True Answer C

Explanation :
Padding is done towards the right-hand-side first when the final string is of even length.

What will be the output of the following Python code?

print('*', "abcde".center(6), '*', sep='')

Question No# : 01 out of 20



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

print('abc'.islower())

Option A. True
Option B. False
Option C. None
Option D. Error
True Answer A

Explanation :
There are no uppercase letters.

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

print('abc'.islower())

Question No# : 02 out of 20



What will be the output of the following Python code?

def fun(n):      if (n > 100):          return n - 5      return fun(fun(n+11));     print(fun(45))

Option A. 50
Option B. 100
Option C. 74
Option D. Infinite loop
True Answer B

Explanation :
The fun(fun(n+11)) part of the code keeps executing until the value of n becomes greater than 100, after which n-5 is returned and printed.

What will be the output of the following Python code?

def fun(n):      if (n > 100):          return n - 5      return fun(fun(n+11));     print(fun(45))

Question No# : 03 out of 20



How are variable length arguments specified in the function heading?

Option A. one star followed by a valid identifier
Option B. one underscore followed by a valid identifier
Option C. two stars followed by a valid identifier
Option D. two underscores followed by a valid identifier
True Answer A

Explanation :
Refer documentation.

How are variable length arguments specified in the function heading?

Question No# : 04 out of 20



Which of the following functions does not necessarily accept only iterables as arguments?

Option A. enumerate()
Option B. all()
Option C. chr()
Option D. max()
True Answer C

Explanation :
The functions enumerate(), all() and max() accept iterables as arguments whereas the function chr() throws an error on receiving an iterable as an argument. Also note that the function chr() accepts only integer values.

Which of the following functions does not necessarily accept only iterables as arguments?

Question No# : 05 out of 20



The function pow(x,y,z) is evaluated as:

Option A. (x**y)**z
Option B. (x**y) / z
Option C. (x**y) % z
Option D. (x**y)*z
True Answer C

Explanation :
The built-in function pow() can accept two or three arguments. When it takes in two arguments, they are evaluated as x**y. When it takes in three arguments, they are evaluated as (x**y)%z.

The function pow(x,y,z) is evaluated as:

Question No# : 06 out of 20



What is the default value of encoding in encode()?

Option A. ascii
Option B. qwerty
Option C. utf-8
Option D. utf-16
True Answer C

Explanation :
The default value of encoding is utf-8.

What is the default value of encoding in encode()?

Question No# : 07 out of 20



What will be the output of the following Python code?

print("abc DEF".capitalize())

Option A. abc def
Option B. ABC DEF
Option C. Abc def
Option D. Abc Def
True Answer C

Explanation :
The first letter of the string is converted to uppercase and the others are converted to lowercase.

What will be the output of the following Python code?

print("abc DEF".capitalize())

Question No# : 08 out of 20



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

print('abcdefcdghcd'.split('cd', 0))

Option A. [‘abcdefcdghcd’]
Option B. ‘abcdefcdghcd’
Option C. error
Option D. none of the mentioned
True Answer A

Explanation :
The given string is split at 0 occurances of the specified substring.

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

print('abcdefcdghcd'.split('cd', 0))

Question No# : 09 out of 20



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

print('abcdefcdghcd'.split('cd', 2))

Option A. [‘ab’, ‘ef’, ‘ghcd’]
Option B. [‘ab’, ‘efcdghcd’]
Option C. [‘abcdef’, ‘ghcd’]
Option D. none of the mentioned
True Answer A

Explanation :
The string is split into a maximum of maxsplit+1 substrings.

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

print('abcdefcdghcd'.split('cd', 2))

Question No# : 10 out of 20



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

print('for'.isidentifier())

Option A. True
Option B. False
Option C. None
Option D. Error
True Answer A

Explanation :
Even keywords are considered as valid identifiers.

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

print('for'.isidentifier())

Question No# : 11 out of 20



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

print('abef'.replace('cd', '12'))

Option A. abef
Option B. 12
Option C. error
Option D. none of the mentioned
True Answer A

Explanation :
The first substring is not present in the given string and hence nothing is replaced.

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

print('abef'.replace('cd', '12'))

Question No# : 12 out of 20



What will be the output of the following Python function?

float(' -12345\n')

Option A.   -12345.0 (5 blank spaces before the number)
Option B. -12345.0
Option C. Error
Option D. -12345.000000000…. (infinite decimal places)
True Answer B

Explanation :
The function float() will remove all the blank spaces and convert the integer to a floating point number. Hence the output will be: -12345.0.

What will be the output of the following Python function?

float(' -12345\n')

Question No# : 13 out of 20



What will be the output of the following Python code?

  1. >>>str1="helloworld"
  2. >>>str1[::-1]

Option A. dlrowolleh
Option B. hello
Option C. world
Option D. helloworld
True Answer A

Explanation :
Execute in shell to verify.

What will be the output of the following Python code?

  1. >>>str1="helloworld"
  2. >>>str1[::-1]

Question No# : 14 out of 20



What will be the output of the following Python code?

print("ccdcddcd".find("c"))

Option A. 4
Option B. 0
Option C. Error
Option D. True
True Answer B

Explanation :
The first position in the given string at which the substring can be found is returned.

What will be the output of the following Python code?

print("ccdcddcd".find("c"))

Question No# : 15 out of 20



The functions which cause side effects to the arguments passed are called

Option A. impure function
Option B. Partial Functions
Option C. Dynamic Functions
Option D. Pure functions
True Answer A

Explanation :

The functions which cause side effects to the arguments passed are called

Question No# : 16 out of 20

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

print('xyyxyyxyxyxxy'.replace('xy', '12', 100))

Option A. xyyxyyxyxyxxy
Option B. 12y12y1212x12
Option C. none of the mentioned
Option D. error
True Answer B

Explanation :
The first 100 occurrences of the given substring are replaced.

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

print('xyyxyyxyxyxxy'.replace('xy', '12', 100))

Question No# : 17 out of 20



What will be the output of the following Python code?

print('ab'.isalpha())

Option A. True
Option B. False
Option C. None
Option D. Error
True Answer A

Explanation :
The string has only letters.

What will be the output of the following Python code?

print('ab'.isalpha())

Question No# : 18 out of 20



What will be the output of the following Python function?

len(["hello",2, 4, 6])

Option A. 4
Option B. 3
Option C. Error
Option D. 6
True Answer A

Explanation :
The function len() returns the length of the number of elements in the iterable. Therefore the output of the function shown above is 4.

What will be the output of the following Python function?

len(["hello",2, 4, 6])

Question No# : 19 out of 20



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

print(''.isdigit())

Option A. True
Option B. False
Option C. None
Option D. Error
True Answer B

Explanation :
If there are no characters then False is returned.

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

print(''.isdigit())

Question No# : 20 out of 20




CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad