Python Certification Exam Preparation Set 51

Which of the following are correct statements?


Options are :

  • *True + 1 evaluates to 2 (Correct)
  • *True and False evaluates to False (Correct)
  • True or False evaluates to False
  • 7+ False evaluates to False

Answer :*True + 1 evaluates to 2 *True and False evaluates to False

Consider the below variable declarations:

x='5'

y='7'


Which of the following expressions are of type str?


Options are :

  • x+y (Correct)
  • x-y
  • x*2 (Correct)
  • x*y

Answer :x+y x*2

Python Certification Exam Preparation Set 57

Which expression would evaluate to 2?


Options are :

  • 11/2
  • 22%5 (Correct)
  • 11//3
  • 2**3

Answer :22%5

What will be the output for the following code snippet?

x=2/2+2**2-2

print(x)


Options are :

  • 2.0
  • .5
  • 3.0 (Correct)
  • 8

Answer :3.0

What will be the output of the following code?


result=str(bool(1) + float(12)/float(2))

print(result)



Options are :

  • 5.0
  • 7.0 (Correct)
  • 4.0
  • SyntaxError

Answer :7.0

Python Certification Exam Preparation Set 7

Consider the following variables:


x='ACID'

y='APPLE'

z='TIGER'


Select the correct code snippet which will give output as CAT:


Options are :

  • print(x[1]+y[1]+z[0])
  • print(x[0]+y[1]+z[0])
  • print(x[1]+y[0]+z[0]) (Correct)
  • None

Answer :print(x[1]+y[0]+z[0])

What can be the ** SECRET ** in the following code?


Options are :

  • dict(fruits -> price)
  • dict(fruits:price)
  • dict(zip(fruits, price)) (Correct)
  • dict(fruits, price)

Answer :dict(zip(fruits, price))

Python Certification Exam Preparation Set 58

What will the code print?


Options are :

  • Banana: 20 Mango: 80 Apple: 50
  • Error: Can not loop through the dict object
  • ('Banana', 20) ('Mango', 80) ('Apple', 50)
  • Banana Mango Apple (Correct)

Answer :Banana Mango Apple

How to delete a key from a dictionary?


Options are :

  • None of the above
  • del dictionary['key'] (Correct)
  • dictionary['key'] = None
  • remove dictionary['key']

Answer :del dictionary['key']

To call the dictionary with the key to get its corresponding value, which of these is more reliable when you are not certain about the existence of the keys?

A: 

>>>  myDict['Key']

B:

>>> myDict.get('Key')


Options are :

  • B (Correct)
  • A

Answer :B

Python Certification Exam Preparation Set 37

Which of the following is used to take a dictionary as an argument of a function?


Options are :

  • **object
  • *args
  • *kwargs
  • **kwargs (Correct)

Answer :**kwargs

Just like [ ] is reserved for <class 'list'> in Python,  { } is explicitly reserved for <class 'dict'> data type


Options are :

  • True
  • False (Correct)

Answer :False

Dictionaries are useful in which of the following approach of problem solving?


Options are :

  • All of the above.
  • Recursion
  • Hash Tables (Correct)
  • Memoization (Correct)

Answer :Hash Tables Memoization

Python Practice Test MCQ Certified Go from 0 to Expert hero Set 9

What is the data type of the "keys" variable in the following code?


Options are :

  • (Correct)

Answer :

What is the complexity of getting a value through the dictionary key?


Options are :

  • O(n)
  • O(log n)
  • O(2n)
  • O(1) (Correct)

Answer :O(1)

How will you add a new key to the dictionary?

Take these credentials for example:

Dictionary = employee

Key to add = salary <class 'str'>

Value for the key = 40000 <class 'int'>


Options are :

  • employee.update({'salary':40000}) (Correct)
  • employee['salary'] = 40000 (Correct)
  • employee.key(salary = 40000)
  • employee.add('salary', 40000)

Answer :employee.update({'salary':40000}) employee['salary'] = 40000

Python Practice Test MCQ Certified Go from 0 to Expert hero Set 24

Which method can be used to merge two dictionaries?

[ For example I want to merge two dictionaries named original and new ]


Options are :

  • original + new
  • update(original, new)
  • original.append(new)
  • original.update(new) (Correct)

Answer :original.update(new)

What will be the output of the following snippet?


Options are :

  • 20 80 50
  • Banana Mango Apple
  • Some Error (Correct)
  • ('Banana', 20) ('Mango', 80) ('Apple', 50)

Answer :Some Error

What will be the output of the following snippet?


Options are :

  • Error: Key not found
  • None
  • None None
  • 'Mango' (Correct)

Answer :'Mango'

Python Certification Exam Preparation Set 65

What will the code print?


Options are :

  • None of the above
  • {1: 2, 3: 4}
  • {1: 2, 3: 4, 5: 6} (Correct)
  • original

Answer :{1: 2, 3: 4, 5: 6}

What is locals( ) ?


Options are :

  • Lists of all the local dictionaries, which can be used to indicate the usage of each of them
  • List of all the variables used in the program.
  • List of all local variables
  • A dictionary object having all the variables in the program as keys and their values as values. (Correct)

Answer :A dictionary object having all the variables in the program as keys and their values as values.

Which of following Internet Modules are supported in Python


Options are :

  • IMAP4
  • NNTP
  • POP3
  • Gopher
  • All of these (Correct)
  • SMTP

Answer :All of these

Python Practice Test MCQ Certified Go from 0 to Expert hero Set 1

re.match search for a match ____ string


Options are :

  • at given index in
  • only at the begning of (Correct)
  • only at the end of
  • everywhere in

Answer :only at the begning of

To match anything other than a digit you can use


Options are :

  • [$0-9]
  • [^0-9] (Correct)
  • [!0-9]
  • [~0-9]

Answer :[^0-9]

When a timeout occurs on a socket, the exception raised is


Options are :

  • socket.timeout (Correct)
  • socket.hererror
  • socket.error
  • socket.gaierror

Answer :socket.timeout

Python Practice Test MCQ Certified Go from 0 to Expert hero Set 20

re.match search for a match ____ string


Options are :

  • only at the begning of
  • at given index in
  • only at the end of
  • everywhere in (Correct)

Answer :everywhere in

Which of following are valid Regular Expression modifiers


Options are :

  • re.I (Correct)
  • re.M (Correct)
  • re.A
  • re.Z
  • re.U (Correct)
  • re.R

Answer :re.I re.M re.U

Multiple threads with in a process can share data with each other ?


Options are :

  • NO
  • YES (Correct)

Answer :YES

Python Practice Test MCQ Certified Go from 0 to Expert hero Set 3

Which of the following are valid methods to control a Queue provided by Queue Module ?


Options are :

  • None of these (Correct)
  • put()
  • full()
  • empty()
  • get()
  • qsize()

Answer :None of these

Local machine name can be obtained using


Options are :

  • os.gethostname()
  • from os import LOCALMCHINENAME
  • socket.gethostname() (Correct)
  • sys.gethostname()

Answer :socket.gethostname()

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions