Tải bản đầy đủ (.docx) (96 trang)

Python online practice test

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (349.76 KB, 96 trang )

Python Online Practice Test - 1

Q. Python is __________?

A. General-purpose interpreted language

B. General-purpose interpreted and interactive language

C. General-purpose interpreted, interactive language and object-oriented language

D. General-purpose interpreted, interactive language, object-oriented and high-level programming language

Correct Answer : OPTION D, General-purpose interpreted, interactive language, object-oriented and high-

level programming language

Q. Python was created by __________?

A. Rasmus Lerdorf B. Guido van Rossum

C. Larry Wall D. Brendan Eich

Correct Answer : OPTION B, Guido van Rossum

Q. Python source code is also available under which license?

A. GPL B. EPL

C. Apache D. MIT

Correct Answer : OPTION A, GPL



Q. Which of the one is an invalid python environment variable?

A. PYTHONPATH B. PYTHONSTARTUP

C. PYTHONCASEOK D. PYTHONLIBRARY

Correct Answer : OPTION D, PYTHONLIBRARY

Q. What is PYTHONHOME?

A. It is an alternative module search path

B. It contains the path of an initialization file containing Python source code

C. It is used in Windows to instruct Python to find the first case-insensitive match in an import statement

D. None of the above

Correct Answer : OPTION A, It is an alternative module search path

Q. What is PYTHONPATH?

A. It is used for installation of Python

B. It tells the Python compiler where to locate the module files imported into a program

C. It tells the Python interpreter where to locate the module files imported into a program

D. None of the above


Correct Answer : OPTION C, It tells the Python interpreter where to locate the module files imported into a

program

Q. What is PYTHONSTARTUP?

A. It is executed every time you start the compiler

B. It is executed every time you start the interpreter

C. It is needed while booting of a particular process

D. None of the above

Correct Answer : OPTION B, It is executed every time you start the interpreter

Q. What is PYTHONCASEOK?

A. It is used to find the first case-sensitive match in an import statement

B. It is used to find the first case-insensitive match in an import statement

C. It is used to find the first case-insensitive match in a package statement

D. None of the above

Correct Answer : OPTION B, It is used to find the first case-insensitive match in an import statement

Q. What is the use of -d command line option?


A. It provides debug input

B. It provides debug output

C. It generates optimized bytecode

D. None of the above

Correct Answer : OPTION B, It provides debug output

Q. What is the extension of Python files?

A. .pt B. .py

C. .pm D. .class

Correct Answer : OPTION B, .py

Q. Which of these is invalid naming convention for Python identifiers?

A. An identifier can start with lowercase letter B. An identifier can start with uppercase letter

C. An identifier can start with a number D. An identifier can start with underscore(_)

Correct Answer : OPTION C, An identifier can start with a number

Q. What is the maximum possible length of an identifier?

A. 20 characters B. 30 characters


C. 50 characters D. None of the above

Correct Answer : OPTION D, None of the above

Q. All keywords in Python are in __________?

A. Lowercase

B. Uppercase

C. Alphanumeric

D. None of the above

Correct Answer : OPTION A, Lowercase

Q. Python keywords can be used as __________?

A. Constant B. Variable

C. Identifier D. None of the above

Correct Answer : OPTION D, None of the above

Q. Which is not a valid keyword?

A. eval B. except

C. Both A and B D. None of these


Correct Answer : OPTION A, eval

Python Online Practice Test - 2

This Test will cover complete Python with very important questions, starting off from basics to advanced

level.

Q. Which one of these is used to comment statements in Python?

A. * B. #

C. @ D. %

Correct Answer : OPTION B, #

Q. How many standard data types does Python support?

A. 3 B. 4

C. 5 D. None of the above

Correct Answer : OPTION C, 5

Q. Which one of these is not a part of standard data types in Python?

A. Numbers B. Character

C. String D. List


Correct Answer : OPTION B, Character

Q. Reference to a number object can be deleted using which statement?

A. del B. delete

C. free D. malloc

Correct Answer : OPTION A, del

Q. Python does not support which of these numerical types?

A. int B. signedInt

C. long D. complex

Correct Answer : OPTION B, signedInt

Q. Which operator is used to concatenate strings in Python?

A. / B. .

C. + D. !

Correct Answer : OPTION C, +

Q. What is the difference between Lists and Arrays?

A. Unlike array, items belonging to Lists can be of different data type


B. Unlike array, list uses parentheses to store items

C. There is no difference between Lists and Arrays

D. None of the above

Correct Answer : OPTION A, Unlike array, items belonging to Lists can be of different data type

Q. Elements in Tuples are stored using __________?

A. [] B. ()

C. {} D. None of the above

Correct Answer : OPTION B, ()

Q. Dictionaries are enclosed by curly braces __________ and values can be assigned and accessed using

square braces __________?

A. [] and {}

B. {} and []

C. () and {}

D. [] and ()

Correct Answer : OPTION B, {} and []


Q. Python supports which types of operators?

A. Arithmetic, Relational, Assignment and Logical operators

B. Arithmetic, Relational, Assignment, Logical and Bitwise operators

C. Arithmetic, Relational, Assignment, Logical, Bitwise and Membership operators

D. Arithmetic, Relational, Assignment, Logical, Bitwise, Membership and Identity operators

Correct Answer : OPTION D, Arithmetic, Relational, Assignment, Logical, Bitwise, Membership and Identity

operators

Q. Which one of these is not an Arithmetic operator?

A. // B. **

C. *** D. None of the above

Correct Answer : OPTION C, ***

Q. Which one of these is not Comparison operator?

A. == B. !=

C. >= D. ===

Correct Answer : OPTION D, ===


Q. Which one of these is not an Assignment operator?

A. **=

B. //=

C. ***=

D. None of the above

Correct Answer : OPTION C, ***=

Q. Which one among these are Membership operator?

A. if and else B. in and not in

C. if and not if D. None of the above

Correct Answer : OPTION B, in and not in

Q. Which one among these are Identity operator?

A. is and not is B. is and not if
D. if and if not
C. is and is not
Correct Answer : OPTION C, is and is not

Python Online Practice Test - 3


This Test will cover complete Python with very important questions, starting off from basics to advanced

level.

Q. What is the order of precedence in python?

A. Parentheses, Exponential, Division, Multiplication, Addition, Subtraction

B. Parentheses, Multiplication, Division, Exponential, Addition, Subtraction

C. Parentheses, Division, Multiplication, Addition, Subtraction, Exponential

D. None of the above

Correct Answer : OPTION A, Parentheses, Exponential, Division, Multiplication, Addition, Subtraction

Q. What is the value of following expression: 3*1**3

A. 1 B. 3

C. 9 D. 27

Correct Answer : OPTION B, 3

Q. Which one of the following have the same precedence?

A. Addition and Subtraction B. Multiplication and Division

C. Both A and B D. None of the above


Correct Answer : OPTION C, Both A and B

Q. What will be the output of the below program?

>>>str="studytonight"
>>>str[:5]
>>>

A. tonight B. study
C. studytonight D. 5
Correct Answer : OPTION B, study
Q. What is the datatype of below statement?

L = [1, 'hello', 'studytonight', 1]

A. Array B. Dictionary

C. List D. Tuple

Correct Answer : OPTION C, List

Q. Which datatype is used to store values in terms of key and value?
= -10
A. Array B. List

C. Class D. Dictionary

Correct Answer : OPTION D, Dictionary

Q. What does ~9 evaluate to?


A. 8 B. -8

C. 10 D. -10

Correct Answer : OPTION D, -10. It is evaluated as –(9+1)

Q. What is the value of following expression: 24//6%3

A. 0 B. 1

C. 2 D. 3

Correct Answer : OPTION B, 1

Q. What is the value of following expression: bin(0x8)

A. 8

B. 1000

C. '0bx1000'

D. '0b1000'

Correct Answer : OPTION D, '0b1000'

Q. What is the output of the code shown below?

bool('False')

bool()

A. True True B. False True
C. False False D. True False
Correct Answer : OPTION D, True False
Q. What is the output of the code shown below?

['study', 'tonight'][bool('')]

A. Error B. No output

C. study D. tonight

Correct Answer : OPTION C, study

Q. What is pass statement in Python?

A. It declares variables B. It defines function
D. None of the above
C. It is a null statement

Correct Answer : OPTION C, It is a null statement

Q. What is the output of the code shown below?

if (9 < 0) and (0 < -9):
print("hello")

elif (9 > 0) or False:
print("study")


else:
print("tonight")

A. hello
B. study

C. tonight
D. None of the above
Correct Answer : OPTION B, study
Q. What is the output of the code shown below?

X="studytonight"
print("05d"%X)

A. 00000studytonight B. studytonight00000
C. Error D. None of the above
Correct Answer : OPTION C, Error
Q. What is the output of the code shown below?

s='{0}, {1}, and {2}'
s.format('hello', 'good', 'morning')

A. 'hello study and tonight' B. 'hello, study, tonight'
D. Error
C. 'hello, study, and tonight'
Correct Answer : OPTION C, 'hello, study, and tonight'

Python Online Practice Test - 4


This Test will cover complete Python with very important questions, starting off from basics to advanced
level.
Q. What is the output of below code?

print(type([1,2]))

A. <class 'tuple'> B. <class 'int'>
C. <class 'set'> D. <class 'list'>
Correct Answer : OPTION D, <class 'list'>
Q. What is the output of below code?

print(type(1/2))

A. <class 'int'> B. <class 'number'>
D. <class 'double'>
C. <class 'float'>
Correct Answer : OPTION C, <class 'float'>
Q. What is the output of below code?

d = lambda p: p * 2
t = lambda p: p * 3
x = 2
x = d(x)
x = t(x)
x = d(x)
print(x)

A. 12 B. 24

C. 36 D. 48


Correct Answer : OPTION B, 24

Q. If PYTHONPATH is set in the environment, which directories are searched for modules?

I) PYTHONPATH directory

II) Current directory

III) Home directory

IV) Installation dependent default path

A. I and IV B. I, II and III

C. I, II, IV D. I, II, III and IV

Correct Answer : OPTION C, I, II and IV

Q. Which one of these is not a loop control statement?

A. break B. continue

C. pass D. def

Correct Answer : OPTION D, def

Q. Which one of the following is a mathematical function?

A. minus(x) B. pow(x)


C. cmp(x,y) D. emp(x)

Correct Answer : OPTION B, pow(x)

Q. What is the output of below code?

True = False
while True:

print(True)
break

A. True B. False
C. Syntax Error D. None of the above
Correct Answer : OPTION C, Syntax Error
Q. What is the output of below code?

x = "studytonight"
while i in x:

print(i, end=" ")

A. studytonight B. study
D. Error
C. tonight
Correct Answer : OPTION D, Error

Q. What is the output of below code?


x = 123
for i in x:

print(i)

A. 1 2 3
B. 123
C. Error
D. None of the above
Correct Answer : OPTION C, Error
Q. What is the output of below code?

for i in '':
print (i)

A. 0 B. Error

C. Null D. None of the above

Correct Answer : OPTION D, None of the above

Q. What is the output of below code?

a = [0, 1, 2, 3]
for a[-1] in a:

print(a[-1])

A. 0 1 2 3 B. 0 1 2 2
D. Error

C. 3 3 3 3
Correct Answer : OPTION B, 0 1 2 2
Q. What is the output of below code?

string = "study tonight"
for i in string.split():

print (i, end=", ")

A. study, tonight B. study, tonight,

C. tonight D. None of the above

Correct Answer : OPTION B, (study, tonight,)

Q. What is the output of below code?

for i in range(2.0):
print(i)

A. 0
B. 1
C. 2
D. Error
Correct Answer : OPTION C, 2
Q. What is the output of below code?

for i in range(0):
print(i)


A. 0 B. No output

C. Error D. None of the above

Correct Answer : OPTION B, No Output

Q. What is the output of below code?

print(r"\nstudytonight")

A. studytonight B. \nstudytonight

C. Error D. None of the above

Correct Answer : OPTION B, \nstudytonight

Python Online Practice Test - 5

This Test will cover complete Python with very important questions, starting off from basics to advanced
level.
Q. A group of developers,were discussing the various options,for interacting with websites,through code.
Following points were stated -
DevA - While using urllib,one can use the method urlencode,for generation of GET query strings.The
Requests module,does the encoding automatically.Urllib2 also has urlencode method.
DevB - Only urllib module, has an urlencode function.Requests module,handles error very
well,whereas,the urllib2 raises an URLError,if the authentication fails.
DevC - Both urllib2 and Requests module,raise an URLError,when authentication fails.The urlencode()
method,is present in urllib2 and not in urllib module.
Mark the correct statement.


A. Dev B is correct about URLError whereas Dev A is wrong about urlencode function

B. Dev C is totally wrong.

C. Dev A is totally correct.

D. Dev C is correct about urlencode function,whereas DevB is wrong about URLError.
Correct Answer : OPTION B, Python Requests module,encode requests automatically.For generation of GET
query strings, method urlencode() present in urllib,is used. No such method is present in urllib2.Urllib2
raises an URLError,if any authentication fails, whereas, Requests module simply returns a response
object,in such a scenario.Thus it handles errors well.
Q. A developer was debugging,a Python program,using the pdb module.Below are some descriptions,of the
debug commands:

1) List the source code. B. <c> , <a> ,<n> ,<r>
2) Add a breakpoint. D. <s> ,
,<d> ,<e>
3) Debug step by step.
4) Resume execution.
Match them with their actual command.

A. <n> ,

,<s> ,<x>

C. <l> , <b> ,<s> ,<c>

Correct Answer : OPTION C, Pdb module,is used to debug a Python program. Different pdb commands,are
used to perform, various operations.
Q. A developer was working on Dictionary data structure in Python3. He executed the following code
snippets:

#1


City1 = {'Pune': 25,'Benguluru':30,'Delhi':40}
City2 = {'Delhi':38}
print(cmp(City1,City2))

#2
City1 = {'Pune': 25,'Benguluru':30,'Delhi':40}
del City1{'Pune'}
print(City1)

Mark the correct output.
A. 1) cmp method does not exists in Python3 2) SyntaxError :invalid syntax
B. 1) 1 2) {'Benguluru':30,'Delhi':40}
C. 1) -1 2) SyntaxError : Key cannot be deleted individually
D. 1) SyntaxError 2) SyntaxError: Delete not supported for dictionary

Correct Answer : OPTION A, The cmp method is present in Python2 but not in Python3. It should be
implemented,by the developer,if needed. The delete function,can be applied,to individual elements of
Dictionary. It should be used as del dict_name(key name).
Q. A developer was solving a worksheet of regex problems. He came across the following:

import re
print((re.split(r'\s','funday is sunday')))
print((re.split(r's','fun is sunday')))
print((re.split(r'\d','sunday 3 times a week')))

Mark the correct output of the print statements.
A. ['funday', 'is', 'sunday'] ['funiunday'] ['sundaytimesaweek']
B. [ 'is', 'sunday'] ['s ','s'] ['3']
C. ['fundayi', 'ss', 'unday'] ['fun', 'i ', 'sunday'] ['sunday','3', ' times a week']
D. ['funday', 'is', 'sunday'] ['fun i', ' ', 'unday'] ['sunday ', ' times a week']

Correct Answer : OPTION D, The \s expression,is used to create a space in the string. When the ' \' is
removed,from the string,only alphabet 's' is removed from the output.The '\d' expression,removes the
digits present in the string.
Q. A developer was teaching his team,about the different socket methods,found in network
programming.Below are few descriptions of the same:
1) This method,sends the User Datagram Protocol(UDP) message.
2) This method,sends a TCP message.
3) This method,receives a UDP message.
4) This method,starts the TCP listener.
Map them with the actual method names.(s is the socket object).
A. s.sendto(), s.send(),s.recevfrom(),s.listen()
B. s.send(), s.send(),s.get(),s.start()
C. s.send(int udp), s.send(int tcp),s.receive(),s.listen()
D. s.sendto(), s.send(),s.recev(),s.start()
Correct Answer : OPTION A, Python has multiple methods,for the server and client sides.Sockets allow to
communicate, between processes, present on same or different machines, or within, a process.

Q. In an interview,developers were asked to mention if the following statements,were true or false.

1) Static analysis tool, that detects bugs,present in Python code is PyChecker.

2) PyModule tool,checks if the python module,meets the coding standards

3) PyFlakes tool,parses the source files,and,points out various errors,present in the code

4) Pylint,is also a quality checker,which checks the length of each line.

Mark the statements as True or False.

A. False, True, True, False. B. True, True, True, True


C. True, False, True, True. D. False, False, False, False.

Correct Answer : OPTION C, Python consists of various tools, that help in finding bugs and errors in the

code.They also help in quality checking and static analysis.

Q. In an exam,following code snippets were provided:

#1
mylist = ['PUNE','MUMBAI','DELHI']
for city in mylist:

city.lower()
print(mylist)

#2
print(bool('False'))

#3
statement="Number of continents are "
value = 7
print(statement+value)

Mark the correct output.
A. 1) ['pune',mumbai','delhi'] 2) False 3) SyntaxError.
B. 1) ['PUNE','MUMBAI','DELHI'] 2) True 3) TypeError
C. 1) TypeError 2) [] 3) Number of continents are 7.
D. 1) SyntaxError 2) TypeError 3) Number of continents are 7.


Correct Answer : OPTION B, The new lower case list,returned is not stored anywhere. Hence the original

mylist list is printed. If any value,is passed to bool() function,it returns true.Concatenation of string and

integer,is not allowed. Hence the 3rd code snippet throws TypeError.

Q. A developer had to mark,the following statements,related to Multithreading in Python,as True or False:

1) RLock can be acquired,by the same thread,multiple times.

2) Acquired Lock,can be released,only by the thread,that acquired it.

3) Acquired RLock,can be released by any thread.

4) If an RLock is acquired 'n' number of times, it should be released,'n' number of times.

Mark the correct output.

A. True, False, False, True. B. False, True, True, False.

C. False, False, True, True D. True, True, False, False.

Correct Answer : OPTION A, RLock can be acquired by the same thread multiple times. It needs to be

released too, the same number of times. Acquired lock,can be released,by any thread,whereas,the

acquired RLock can be released only by the thread that acquired it.

Q. A developer was trying to parse a XML document in Python code. Mark the correct steps,that, he needs


to implement:

1) The xml.dom.minidom module,should be imported, to parse a XML file.

2) The parseXML function,is used to load and parse the XML file.

3) The standard DOM function,getElementsByTagName can be used to get XML tags.

4) The firstChild.name,can be used to print,the name of the firstchild,of the document node.

Mark the correct answer.

A. 2nd and 3rd are correct steps. 1st and 4th are incorrect.

B. All steps except 4th are valid.

C. 1st and 3rd are correct steps. 2nd and 4th are incorrect

D. Except 2nd all steps are valid.

Correct Answer : OPTION C, The xml.dom.minidom module,should be imported, to parse a XML file.The

xml.dom.minidom.parse(xml name) function,is used to load and parse the XML file. The

firstChild.tagname,can be used to print,the name of the firstchild of the document node.

Q. Below are mentioned, a few points about different Python frameworks:

1) External libraries are required for database administration and templating


2) Bootstrapping tools are not present

3) Provides flexibility,and,allows the developer, to choose right tools,for their projects.

4) It has built-in modules for routing,authentication and templating.

Guess the name of the framework from the description

A. Django, Pyramid, Django, Flask. B. Django, Pyramid, Pyramid, Flask.

C. Django, Flask, Flask, Pyramid. D. Pyramid, Flask, Pyramid, Django.

Correct Answer : OPTION D, Pyramid,Django and Flask are a few web frameworks built in Python. Flask

framework is mainly used for building small applications whereas Django and Pyramid are meant for larger

ones

Python Online Practice Test - 6

This Test will cover complete Python with very important questions, starting off from basics to advanced

level.

Q.In an exam, the developers were provided,the following statements,regarding File copying,using system

shell utilities:

a) The shutil.copy2() function, is same as shutil.copy(), except that copy2(),copies the file metadata,along


with the file.

b) When using copy2() function, one must specify the file buffer.

c) The copy2() function,does not copies,the permission bits,to the destination file.

d) If we want an exact duplicate copy of a file, the copy() function,should be used,instead of copy2().

Mark them if they are appropriate as Yes or No.

A. Yes, No, Yes, Yes B. No, Yes, No, Yes

C. Yes, No, No, No D. No, Yes, Yes, No

Correct Answer : OPTION C, The shutil copy() and copy2() functions,are almost same.Copy2(),copies the

file metadata,along with the file.There is no need,to specify,the file buffer.It copies the permission bits,of

the destination file as well.If we want,an exact duplicate copy of a file, then, copy2() should be used.

Q. Below are mentioned,descriptions of Python file extensions:

a) Python script archive file.

b) Windows DLL file.

c) A python file created with optimizations.

d) The compiled bytecode of the file.


Mark them correctly with the actual file extensions.

A. .pyz, .pywdl, .pyop, .pyc B. .pyr, .pydl, .py, .py

C. .pya, .pyw, .pyz, .py D. .pyz, .pyd, .pyo, .pyc

Correct Answer : OPTION D, Python scripts can have many extensions as mentioned above.

Q. A developer was checking,her Python code,using Tabnanny utility tool. She knew,that tool helped,in

checking ambiguous code.She was given,some points to check:

1) Analyse white-space related issues.

2) Code should print verbose messages.

3) Display names of files,that contain issues,related to whitespaces.

Which methods,of the tool should she use?

Mark the correct answer.

A. tabnanny.checkdir(dir/file name), tabnanny.explicit, tabnanny.filename.

B. tabnanny.check(dir/file name), tabnanny.verbose, tabnanny.filename_only

C. tabnanny.whitepsc(),tabnanny.verbose_message,tabnanny.file_name

D. tabnanny.checkfile(dir/file name), tabnanny.msgverbose, tabnanny.file_name_only.


Correct Answer : OPTION B, The tabnanny module, mentions ambiguous code. It tells if any weird

combination,of tabs or spaces, are found in the code.

Q. In an exam,students were provided following code snippets:

#1
a=1
if a<1:

print("2")
elif a<=1:

print("3")
else:

print("1")

#2
def div(firstnum,secondnum):

assert secondnum!=0, "This is divide by zero"
return firstnum/secondnum


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×