Quiz
PyPreparation
Create a free account to finish this quiz
Save your progress and see your final score.
Already have an account? Sign in
Questions in this quiz (59)
1Which of the following is invalid?
- A__str__ = 1
- Bnone of the mentioned
- C__a = 1
- D_a = 1
2Who created the Python?
- APython Charm
- BMads Torgersen
- CRick Mascitti
- DGuido van Rossum
3We can create a dictionary which contains dictionatries. True or false?
- ATrue
- BFalse
4Is Python case sencitive when dealing with identifiers?
- Anone of the mentioned
- Bmachine dependent
- Cno
- Dyes
5What is a correct syntax to output "Some like it hot" in Python?
- Aprint "Some like it hot"
- B"Some like it hot"
- Cp("Some like it hot")
- Decho"Some like it hot"
- Eprint("Some like it hot")
6What will be the output of the given code snippet?

- ANo, 'A' is not int the letters sequence
- BIt will terminate with en error
- CIt will not print anything
- DYes, 'A' is in the letters sequence
7What will be the output of this code?
a = "Cyber"
b = "Pank"
c = a+b
print(c)- ATrue
- BFalse
- CCyberPank
- DError
- ECyber Pank
8Choose the correct output formatting
- Aprint("My full name is %s%s" % (a,b)), where a = 'a'; b = '6'
- Bprint("My full name is %s%s" % (a,b)), where a = 5, b = 6
- Cprint("My full name is %f%f" % (a,b)), where a = 'a'; b = '6'
- Dprint("My full name is %i%i" % (a,b)), where a = 'a'; b = '6'
9Which of these is not a core datatype?
- ALists
- BDictionary
- CTuples
- DClass
10Python requires us to declare types such as int, string, and char[] before declaring a variable
- ATrue
- BFalse
11What will be the output of the following Python code snippet?
bool("False")
bool()- AFalse False
- BTrue False
- CFalse True
- DTrue True
12Operators with the same precedence are evaluated in which manner?
- ACan't say
- BNone of the mentioned
- CLeft to Right
- DRight to Left
13Adding comments to your code:
- A// and /**/
- B///*//*
- C* and """
- D&/t -- -->
14Which collection does not allow duplicate members?
- Adictionary
- Bset
- Clist
- Dnumpy array
- Etuple
15Evaluate the given expression if A = 16 and B = 15.
A % B // A- A1
- B0
- C0.0
- D1.0
16Which of the folllowing is true for variable names in Python?
- Aunlimited length
- Bunderscore and ampersand are the only two special characters allowed
- Cnone of the mentioned
- Dall private mmbers must have leading and trailing underscores
17You have to install SQLite3 database by executing following command:
- Anone of the above
- Bpip install sqlitedb
- Cpip install --update sqlite
- Dpip install sqlight3
- Eall of the above are egligible
18The commit() method:
- AAll of the above
- BDeletes all the operations declared before t
- CNone of the above
- DSaves all the operations declared before t
19The execute() method:
- ANone of the above
- BExecutes the SQL query
- CSaves all the operations declared befor it
- DAll of the above
20You CANNOT reverse a queue. True or False?
- ATrue
- BFalse
21Which collection is ordered, changeable, and allows duplicate members?
- Aset
- Bnumpy array
- Clist
- Dtuple
- Edictionary
22What will be the output
my_list = list('A', 'B', 'C')
print(my_list[1:2])- A['B']
- B['A', 'B', 'C']
- CIt will terminate with an error
- D['B', 'C']
- E['C']
23What is a cursor in database?
- Aan instance representing an object from a table
- Ba pointer to a specific row within a query result
- Ca class
24Why are variable names beginning with an underscore discouraged?
- Athey confuse the interpreter
- Bthey are used to indicate a private variables of a class
- Cthey are used to indicate global variables
- Dthey slow down execution
25What will be the output of the following Python code?
if(9<0) and (0<-9):
print("hello")
elif (9>0) or False:
print("good")
else: print("bad")- Ahello
- Berror
- Cbad
- Dgood
26What is Python?
- APython is an interpreted, object-oriented, low-level programming language with static semantics.
- BPython is an interpreted, object-oriented, high-level programming language with dynamic semantics.
- CPython is an compiled, object-oriented, high-level programming language with staticsemantics.
- DPython is an interpreted, object-oriented, high-level programming language with static semantics.
27What does the __init__() function do in Python? Choose one
- ANone of the above
- BInitializes the class for use
- CThis function is called when a new object is instantiated
- DInitializes all the data attributes to zero when called.
28Which code snippet is most likely to terminate with an error?
- Ax = "5"
print(bool(x)) - Bx = "5j"
print(int(x)) - Cx = "5"
print(list(x)) - Dx = "5"
print(int(x)) - Ex = "5"
print(float(x))
- Ax = "5"
29Choose the correct output of the code: print("{1}, {0}, {2}".format(5,8,'a'))
- A5,a,8
- Ba,8,5
- C5,8,a
- D8,5,a
30What is print()?
- ABuilt-in fuction with arguments print(object)
- BBuilt-in fuction with arguments print(object, sep="", end="\n", file = sys.stdout, flush=False)
- CBuilt-in fuction with arguments print(file = sys.stdout, flush=False)
- DSpecial variable to output
31Which of the following is an invalid statement?
- Ad,e,f = 6000,7000,8000
- Bd e f=6000 7000 8000
- Cdef=5,000,000
- Dd_e_f=7,000,000
32What will be the output of the following Python expression if x = 456
print("%-06d"%x)- A456000
- Berror
- C000456
- D456
33A class which child inherits from is called
- Aa superclass
- Ban independent class
- Ca subclass
- Da sibling class
34How can you access an items in dictionary?
- AYou can access the items of a dictionary by referring to its key name, inside square brackets
- BYou cannot access items in dictionary
- CYou can use specific function dictionary update() for that
- DYou can access the items of a dictionary by referring to its index, inside square brackets
35Which of the following is not a keyword?
- Anonlocal
- Beval
- Cpass
- Dassert
36Which code snippet provides avoidance of special characters in Python
- Aprint(t"Yes you could use it before")
- Bprint("Yes /"you could use /" it before")
- Cprint(r"Yes "you could use it" before")
- Dprint("Yes ' "you could use it' " before")
37What is the output
print("Some like it hot"[2:7])
- Alike
- Be like
- Cme li
- Dlike i
- Eme lik
38Output

- A2 3
- BNone None
- C-1 -2
- D1 2
39Which code snippet will print only the values in cars dictionary?
- Afor x in cars:
print (x) - Bfor x in cars.items():
print(x) - Cfor x in cars:
print(cars) - Dfor x in cars:
print(cars[x])
- Afor x in cars:
40Which method can be used to remove any whitespace from both the beginning and the end of a string
- Atrim()
- Bstrip()
- Clen()
- Dptrim()
- Esplit()
41What is the right syntax of super usage in inheritance?
- Asuper(Child, self)__init__(self)
- Bsuper(Parent, self)__init__(self)
- Csuper(Child, self)__init__()
- Dsuper(Parent, self)__init__()
4211. What will be the output of the following Python code?
>>> a=dict()
>>> a[1]- Aa) An exception is thrown since the dictionary is empty
- Bb) ‘ ‘
4312. What will be the output of the following Python code?
>>> import collections
>>> a=dict()
>>> a=collections.defaultdict(int)
>>> a[1]- Aa) 1
- B0
- Cc) An exception is thrown
4410. What will be the output of the following Python code?
>>> a={i: 'A' + str(i) for i in range(5)}
>>> a- Ad) {0: ‘0’, 1: ‘1’, 2: ‘2’, 3: ‘3’, 4: ‘4’}
- Bb) {0: ‘A0’, 1: ‘A1’, 2: ‘A2’, 3: ‘A3’, 4: ‘A4’}
- Ca) An exception is thrown
458. If b is a dictionary, what does any(b) do?
- Aa) Returns True if any key of the dictionary is true
- Bb) Returns False if dictionary is empty
- Cc) Returns True if all keys of the dictionary are true
- Dd) Method any() doesn’t exist for dictionary
46What will be the output of the following Python code?
>>> a={}
>>> a.fromkeys([1,2,3],"check")- Ab) {1:”check”,2:”check”,3:”check”}
- Bc) “check”
- Ca) Syntax error
- Dd) {1:None,2:None,3:None}
473. If a is a dictionary with some key-value pairs, what does a.popitem() do?
- Aa) Removes an arbitrary element
- Bb) Removes all the key-value pairs
- Cc) Removes the key-value pair for the key given as an argument
- Dd) Invalid method for dictionary
481. Which of the statements about dictionary values if false?
- Ac) Values of a dictionary must be unique
- BMore than one key can have the same value
- CThe values of the dictionary can be accessed as dict[key]
- DValues of a dictionary can be a mixture of letters and numbers
4911. Which of the following isn’t true about dictionary keys?
- Ac) Keys must be integers
- Bd) When duplicate keys encountered, the last assignment wins
501. Which of these about a dictionary is false?
- Aa) The values of a dictionary can be accessed using keys
- Bb) The keys of a dictionary can be accessed using values
51What will be the output of the following Python code, if s1= {1, 2, 3}?
s1.issubset(s1)- Aa) True
- Bd) False
52What will be the output of the following Python code?
a=set('abc')
b=set('def')
b.intersection_update(a)
a
b- Aa)
set()
(‘e’, ‘d’, ‘f’} - Bb)
{}
{} - Cc)
{‘b’, ‘c’, ‘a’}
set()
- Aa)
53If we have two sets, s1 and s2, and we want to check if all the elements of s1 are present in s2 or not, we can use the function:
- Aa) s2.issubset(s1)
- Bb) s2.issuperset(s1)
54The difference between the functions discard and remove is that:
- ARemove throws an error if the specified element is not present in the set whereas discard does not throw an error in case of absence of the specified element
- BRemove removes the last element of the set whereas discard removes the first element of the set
- CDiscard throws an error if the specified element is not present in the set whereas remove does not throw an error in case of absence of the specified element
55What is the maximum possible length of an identifier?
- Aa) 31 characters
- Bb) 63 characters
- Cc) 79 characters
56What is the order of precedence in python?
i) Parentheses ii) Exponential iii) Multiplication iv) Division v) Addition vi) Subtraction- Aa) i,ii,iii,iv,v,vi
- Bb) ii,i,iii,iv,v,vi
57Which one of the following has the same precedence level?
- Aa) Addition and Subtraction
- Bb) Multiplication, Division and Addition
58What is the return value of trunc()?
- Aint
- Bbool
59It is not possible for the two’s complement value to be equal to the original value in any case.
- ATrue
- BFalse
Information
- Description
- Quiz on PyPreparation, created by Mark Kim on 18/12/2019.
- Author
- Mark Kim
- Language
- English
- Views
- 32
- Rating
- No ratings yet Rate this quiz