Python/Python Mcq Set 12 Sample Test,Sample questions

Question:
 How are required arguments specified in the function heading?

1. identifier followed by an equal to sign and the default value

2. identifier followed by the default value within backticks (“)

3. identifier followed by the default value within square brackets ([])

4. identifier


Question:
 What will be the output of the following Python code?

def foo(k):
    k = [1]
q = [0]
foo(q)
print(q)

1.[0]

2.[1]

3.[1, 0]

4.[0, 1]


Question:
 What will be the output of the following Python code?
i=0
def change(i):
   i=i+1
   return i
change(1)
print(i)

1. 1

2. Nothing is displayed

3. 0

4.An exception is thrown


Question:
 Which are the advantages of functions in python?

1.Reducing duplication of code

2.Decomposing complex problems into simpler pieces

3.Improving clarity of the code

4. All of the mentioned


Question:
 Which of the following is a feature of DocString?

1.Provide a convenient way of associating documentation with Python modules, functions, classes, and methods

2.All functions should have a docstring

3.Docstrings can be accessed by the __doc__ attribute on objects

4.All of the mentioned


Question:
hat will be the output of the following Python code?

def change(one, *two):
   print(type(two))
change(1,2,3,4)

1.Integer

2. Tuple

3.Dictionary

4.An exception is thrown


Question:
How are default arguments specified in the function heading?

1. identifier followed by an equal to sign and the default value

2.identifier followed by the default value within backticks (“)

3.identifier followed by the default value within square brackets ([])

4.identifier


Question:
How are keyword arguments specified in the function heading?

1.one-star followed by a valid identifier

2.one underscore followed by a valid identifier

3.two stars followed by a valid identifier

4. two underscores followed by a valid identifier


Question:
How are variable length arguments specified in the function heading?

1.one star followed by a valid identifier

2.one underscore followed by a valid identifier

3. two stars followed by a valid identifier

4.two underscores followed by a valid identifier


Question:
How many keyword arguments can be passed to a function in a single function call?

1.zero

2.one

3.zero or more

4.One or more


Question:
Suppose there is a list such that: l=[2,3,4]. If we want to print this list in reverse order, which of the following methods should be used?

1.reverse(l)

2.list(reverse[(l)])

3.reversed(l)

4. list(reversed(l))


Question:
What are the two main types of functions?

1.Custom function

2. Built-in function & User defined function

3.User function

4.System function


Question:
What is a variable defined inside a function referred to as?

1. A global variable

2.A volatile variable

3.A local variable

4.An automatic variable


Question:
What is the length of sys.argv?

1. number of arguments

2.number of arguments + 1

3.number of arguments – 1

4.none of the mentioned


Question:
What is the type of each element in sys.argv?

1.set

2.list

3.tuple

4.String


Question:
What is the type of sys.argv?

1. set

2.list

3. tuple

4.string


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

1.null

2.you cannot access it

3.the program’s name

4.the first argument


Question:
What will be the output of the following Python code?

def a(b):
    b = b + [5]
 
c = [1, 2, 3, 4]
a(c)
print(len(c))

1.4

2. 5

3. 1

4. An exception is thrown


Question:
What will be the output of the following Python code?

def change(i = 1, j = 2):
    i = i + j
    j = j + 1
    print(i, j)
change(j = 1, i = 2)

1.An exception is thrown because of conflicting values

2.1 2

3.3 3

4.3 2


Question:
What will be the output of the following Python code?

def display(b, n):
    while n > 0:
        print(b,end="")
        n=n-1
display('z',3)

1. zzz

2. zz

3.An exception is executed

4. Infinite loop


Question:
What will be the output of the following Python code?

def f(x, y, z): return x + y + z
f(2, 30, 400)

1. 432

2.24000

3.430

4.No output


Question:
What will be the output of the following Python code?

def find(a, **b):
   print(type(b))
find('letters',A='1',B='2')

1. String

2. Tuple

3.Dictionary

4.An exception is thrown


Question:
What will be the output of the following Python code?

def foo():
    return total + 1
total = 0
print(foo())

1. 0

2.1

3.error

4.none of the mentioned


Question:
What will be the output of the following Python code?

def foo():
    total += 1
    return total
total = 0
print(foo())

1.0

2. 1

3.error

4.none of the mentioned


Question:
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])

1.3 1

2.1 3

3.error

4. None of the mentioned


Question:
What will be the output of the following Python code?

def foo(i, x=[]):
    x.append(i)
    return x
for i in range(3):
    print(foo(i))

1.[0] [1] [2]

2.[0] [0, 1] [0, 1, 2]

3.[1] [2] [3]

4.[1] [1, 2] [1, 2, 3]


Question:
What will be the output of the following Python code?

def foo(i, x=[]):
    x.append(x.append(i))
    return x
for i in range(3):
    y = foo(i)
print(y)

1.[[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]]

2.[[0], [[0], 1], [[0], [[0], 1], 2]]

3.[0, None, 1, None, 2, None]

4.[[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]]


Question:
What will be the output of the following Python code?

def foo(x):
    x = ['def', 'abc']
    return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))

1. True

2.False

3.None

4. error


Question:
What will be the output of the following Python code?

def foo(x):
    x[0] = ['def']
    x[1] = ['abc']
    return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))

1. True

2.False

3.None

4.error


Question:
What will be the output of the following Python code?

def maximum(x, y):
    if x > y:
        return x
    elif x == y:
        return 'The numbers are equal'
    else:
        return y
 
print(maximum(2, 3))

1. 2

2.3

3.The numbers are equal

4.None of the mentioned


Question:
What will be the output of the following Python code?

def writer():
	title = 'Sir'
	name = (lambda x:title + ' ' + x)
	return name
 
who = writer()
who('Arthur')

1.Arthur Sir

2.Sir Arthur

3.Arthur

4.none of the mentioned


Question:
What will be the output of the following Python code?

min = (lambda x, y: x if x < y else y)
 min(101*99, 102*98)

1. 9997

2.9999

3.9996

4. None of the mentioned


Question:
What will be the output of the following Python code?

x = 50
def func():
    global x
    print('x is', x)
    x = 2
    print('Changed global x to', x)
func()
print('Value of x is', x)

1.x is 50 Changed global x to 2 Value of x is 50

2.x is 50 Changed global x to 2 Value of x is 2

3.x is 50 Changed global x to 50 Value of x is 50

4.none of the mentioned


Question:
What will be the output of the following Python code?
def cube(x):
    return x * x * x      
x = cube(3)    
print x

1. 9

2.3

3.27

4.30


Question:
What will be the output of the following Python code?
def foo(k):
    k[0] = 1
q = [0]
foo(q)
print(q)

1.[0]

2. [1]

3.[1, 0]

4.[0, 1]


Question:
What will be the output of the following Python code?
def printMax(a, b):
    if a > b:
        print(a, 'is maximum')
    elif a == b:
        print(a, 'is equal to', b)
    else:
        print(b, 'is maximum')
printMax(3, 4)

1.3

2. 4

3.4 is maximum

4.none of the mentioned


Question:
What will be the output of the following Python code?
def say(message, times = 1):
    print(message * times)
say('Hello')
say('World', 5)

1.Hello WorldWorldWorldWorldWorld

2.Hello World 5

3.Hello World,World,World,World,World

4.Hello HelloHelloHelloHelloHello


Question:
What will be the output of the following Python code?
def sayHello():
    print('Hello World!') 
sayHello() 
sayHello()

1.Hello World! Hello World!

2.'Hello World!' 'Hello World!'

3.Hello Hello

4. None of the mentioned


Question:
What will be the output of the following Python code?
lamb = lambda x: x ** 3
print(lamb(5))

1. 15

2.555

3. 125

4. None of the mentioned


Question:
What will be the output of the following Python code?
x = 50
def func(x):
    print('x is', x)
    x = 2
    print('Changed local x to', x)
func(x)
print('x is now', x)

1.x is 50 Changed local x to 2 x is now 50

2.x is 50 Changed local x to 2 x is now 2

3.x is 50 Changed local x to 2 x is now 100

4.none of the mentioned


Question:
What will be the output of the following Python function?

hex(15)

1.f

2. 0xF

3.0Xf

4.0xf


Question:
What will be the output of the following Python function?
float('   -12345
')
(Note that the number of blank spaces before the number is 5)

1. -12345.0 (5 blank spaces before the number)

2. -12345.0

3.Error

4.-12345.000000000…. (infinite decimal places)


Question:
Where are the arguments received from the command line stored?

1.sys.argv

2.os.argv

3.argv

4.none of the mentioned


Question:
Which keyword is used for function?

1.Fun

2. Define

3.Def

4. Function


Question:
Which module in the python standard library parses options received from the command line?

1.getopt

2.os

3.getarg

4.main


Question:
Which of the following functions accepts only integers as arguments?

1.ord()

2.min()

3.chr()

4.any()


Question:
Which of the following functions does not throw an error?

1.ord()

2.ord(‘ ‘)

3.ord(”)

4.ord(“”)


Question:
Which of the following functions will not result in an error when no arguments are passed to it?

1.min()

2.divmod()

3.all()

4. float()


Question:
Which of the following is the use of function in python?

1.Functions are reusable pieces of programs

2. Functions don’t provide better modularity for your application

3.you can’t also create your own functions

4.all of the mentioned


Question:
Which of the following refers to mathematical function?

1.sqrt

2.rhombus

3.add

4.rhombus


More MCQS

  1. Python MCQS - Function
  2. Python MCQS - GUI in python
  3. Python MCQS - Operators
  4. Python MCQS - Data type in python
  5. Python MCQS - loops in python
  6. Python MCQS - Numpy
  7. Python MCQS - sqlite3
  8. Python MCQS - Library
  9. Python MCQS - Pandas
  10. Python MCQs
  11. Dictionary Python MCQ set 1
  12. Dictionary Python MCQ set 2
  13. MCQ For Python Fundamentals
  14. MCQ Introduction to Python Section 1
  15. MCQ Introduction to Python Section 2
  16. MCQ Introduction to Python Section 3
  17. MCQ on Flow of Control in Python Set 1
  18. MCQ on Flow of Control in Python Set 2
  19. MCQ on Python String Set 1
  20. File Handling in Python section 1
  21. File Handling in Python section 2
  22. Python Functions MCQS Set 1
  23. Python Functions MCQS Set 2
  24. MCQ on List in Python
  25. Pandas MCQ Questions Set 1
  26. Pandas MCQ Questions Set 2
  27. Tuple MCQ in Python
  28. Python dataframe MCQ
  29. Python Mcq Set 1
  30. Python Mcq Set 2
  31. Python Mcq Set 3
  32. Python Mcq Set 4
  33. Python Mcq Set 5
  34. Python Mcq Set 6
  35. Python Mcq Set 7
  36. Python Mcq Set 8
  37. Python Mcq Set 9
  38. Python Mcq Set 10
  39. Python Mcq Set 11
  40. Python Mcq Set 12
  41. Python Mcq Set 13
  42. Python Mcq Set 14
  43. Python Mcq Set 15
  44. Python Mcq Set 16
  45. Python Mcq Set 17
  46. Python Mcq Set 18
  47. Python Mcq Set 19
  48. Python Mcq Set 20
  49. Python Mcq Set 21
  50. Python MCQ
  51. Python MCQ Questions with Answer
  52. Python Practice Papers
  53. python mcq question and answer
  54. Test
Search
Olete Team
Online Exam TestTop Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on Online Exam Testwebsite is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!