QUIZ ON : PROGRAMMING AND PROBLEM SOLVING THROUGH PYTHON - FUNCTIONS IN PYTHON

FUNCTIONS IN PYTHON

00:00:00

What will be the output of the following Python code?

  1. >>>example = "helle"
  2. >>>example.rfind("e")

Option A. -1
Option B. 4
Option C. 3
Option D. 1
True Answer B

Explanation :
Returns highest index.

What will be the output of the following Python code?

  1. >>>example = "helle"
  2. >>>example.rfind("e")

Question No# : 01 out of 20



What will be the output of the following Python code?

print('*', "abcdef".center(7), '*')

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

Explanation :
Padding is done towards the left-hand-side first when the final string is of odd length. Extra spaces are present since we haven’t overridden the value of sep.

What will be the output of the following Python code?

print('*', "abcdef".center(7), '*')

Question No# : 02 out of 20



Which is the most appropriate definition for recursion?

Option A. A function that calls itself
Option B. A function execution instance that calls another execution instance of the same function
Option C. A class method that calls another class method
Option D. An in-built method that is automatically called
True Answer B

Explanation :
The appropriate definition for a recursive function is a function execution instance that calls another execution instance of the same function either directly or indirectly.

Which is the most appropriate definition for recursion?

Question No# : 03 out of 20



What will be the output of the following Python code?

print("abcdef".find("cd") == "cd" in "abcdef")

Option A. True
Option B. False
Option C. Error
Option D. None of the mentioned
True Answer B

Explanation :
The function find() returns the position of the sunstring in the given string whereas the in keyword returns a value of Boolean type.

What will be the output of the following Python code?

print("abcdef".find("cd") == "cd" in "abcdef")

Question No# : 04 out of 20



What will be the output of the following Python code?

print("xyyzxyzxzxyy".count('xyy', 2, 11))

Option A. 2
Option B. 0
Option C. 1
Option D. error
True Answer B

Explanation :
Counts the number of times the substring ‘xyy’ is present in the given string, starting from position 2 and ending at position 11.

What will be the output of the following Python code?

print("xyyzxyzxzxyy".count('xyy', 2, 11))

Question No# : 05 out of 20



What happens if a local variable exists with the same name as the global variable you want to access?

Option A. Error
Option B. The local variable is shadowed
Option C. Undefined behavior
Option D. The global variable is shadowed
True Answer D

Explanation :
If a local variable exists with the same name as the local variable that you want to access, then the global variable is shadowed. That is, preference is given to the local variable.

What happens if a local variable exists with the same name as the global variable you want to access?

Question No# : 06 out of 20



The small sections of code that are used to perform a particular task is called

Option A. Subroutines
Option B. Files
Option C. Pseudo code
Option D. Modules
True Answer A

Explanation :

The small sections of code that are used to perform a particular task is called

Question No# : 07 out of 20

What is the value stored in sys.argv[0]?

Option A. null
Option B. you cannot access it
Option C. the program’s name
Option D. the first argument
True Answer C

Explanation :
Refer documentation.

What is the value stored in sys.argv[0]?

Question No# : 08 out of 20



How are default arguments specified in the function heading?

Option A. identifier followed by an equal to sign and the default value
Option B. identifier followed by the default value within backticks (“)
Option C. identifier followed by the default value within square brackets ([])
Option D. identifier
True Answer A

Explanation :
Refer documentation.

How are default arguments specified in the function heading?

Question No# : 09 out of 20



What will be the output of the following Python code?

print("xyyzxyzxzxyy".endswith("xyy", 0, 2))

Option A. 0
Option B. 1
Option C. True
Option D. False
True Answer D

Explanation :
The function returns False if the given string does not end with the specified substring.

What will be the output of the following Python code?

print("xyyzxyzxzxyy".endswith("xyy", 0, 2))

Question No# : 10 out of 20



What will be the output of the following Python function?

any([2>8, 4>2, 1>2])

Option A. Error
Option B. True
Option C. False
Option D. 4>2
True Answer B

Explanation :
The built-in function any() returns true if any or more of the elements of the iterable is true (non zero), If all the elements are zero, it returns false.

What will be the output of the following Python function?

any([2>8, 4>2, 1>2])

Question No# : 11 out of 20



What will be the output of the following Python code?

print("xyyzxyzxzxyy".count('yy', 1))

Option A. 2
Option B. 0
Option C. 1
Option D. none of the mentioned
True Answer A

Explanation :
Counts the number of times the substring ‘yy’ is present in the given string, starting from position 1.

What will be the output of the following Python code?

print("xyyzxyzxzxyy".count('yy', 1))

Question No# : 12 out of 20



The functions which will give exact result when same arguments are passed are called

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

Explanation :

The functions which will give exact result when same arguments are passed are called

Question No# : 13 out of 20

What will be the output of the following Python statement?

>>>print(chr(ord('b')+1))

Option A. a
Option B. b
Option C. c
Option D. A
True Answer C

Explanation :
Execute in the shell to verify.

What will be the output of the following Python statement?

>>>print(chr(ord('b')+1))

Question No# : 14 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# : 15 out of 20



Which of the following functions accepts only integers as arguments?

Option A. ord()
Option B. min()
Option C. chr()
Option D. any()
True Answer C

Explanation :
The function chr() accepts only integers as arguments. The function ord() accepts only strings. The functions min() and max() can accept floating point as well as integer arguments.

Which of the following functions accepts only integers as arguments?

Question No# : 16 out of 20



What will be the output of the following Python code?

print("ab\tcd\tef".expandtabs('+'))

Option A. ab+cd+ef
Option B. ab++++++++cd++++++++ef
Option C. ab cd ef
Option D. none of the mentioned
True Answer D

Explanation :
TypeError, an integer should be passed as an argument.

What will be the output of the following Python code?

print("ab\tcd\tef".expandtabs('+'))

Question No# : 17 out of 20



The variables in a function definition are called as

Option A. Subroutines
Option B. Function
Option C. Definition
Option D. Parameters
True Answer D

Explanation :

The variables in a function definition are called as

Question No# : 18 out of 20

What will be the output of the following Python code?

def foo(fname, val):      print(fname(val))  foo(max, [1, 2, 3])  foo(min, [1, 2, 3])

Option A. 3 1
Option B. 1 3
Option C. error
Option D. none of the mentioned
True Answer A

Explanation :
It is possible to pass function names as arguments to other functions.

What will be the output of the following Python code?

def foo(fname, val):      print(fname(val))  foo(max, [1, 2, 3])  foo(min, [1, 2, 3])

Question No# : 19 out of 20



How are required arguments specified in the function heading?

Option A. identifier followed by an equal to sign and the default value
Option B. identifier followed by the default value within backticks (“)
Option C. identifier followed by the default value within square brackets ([])
Option D. identifier
True Answer D

Explanation :
Refer documentation.

How are required arguments specified in the function heading?

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