Python questions in pdf for data science interviews. A question bank on python for practice. In Reddit and Sanfoundry, you will get random questions, but here these are in order. The difficult to answer questions explained clearly.
Breaking the Kubernetes Kill Chain: Host Path Mount
Python Tutorial Questions part-1
1. Python Questions & Answers
Tutorial Part-1
Q.1. What is the role of keywords in Python language? List keywords provided by
Python.
A) The Keywords in Python you can say as reserved words. All keywords are with Small
case. Only 3 keywords are not Small case. Those are True, False and None
and False nonlocal
as finally not
assert for or
break from pass
class global raise
continue if return
def import True
del in try
elif is while
else lambda with
except None yield
Q.2. What is an identifier? How will you differentiate it from a variable?
A). Identifier is an user defined variable. This can be name given to Function, Class, and
Variable by user. The length can be any length. It cannot start with numbers. And, it cannot
contain special chars.
Q.3. what is a variable? State the rules used to define a variable in Python language.
A). It is an user-defined variable. Basically it indicates a data-type. In Python, you can define
dynamically where you want. The data type it assigns dynamically according to value you
assigned to a variable. Example Char or Int
2. Q.4. Why documentation is necessary in a language? How documentation can be
performed in Python?
A). In Python, to make developer understand the logic, in the middle, you can write
comments. These comments start with ‘#’. This is called documentation.
Q.5. Explain the significance of data types in Python language?
A). The value you assigned to a variable defined by you, says that, that particular type applies
to that variable.
Python supports 7 data types – Number, String, List, Tuple, Set, Dictionary and File
Q.6. Identify the data type that appropriately describes the data given below:
a. 32.e10 ➔ Complex
b. -8.56e100 ➔ Float
c. 34.j ➔ Complex
d. -876 ➔ Int
e. 432 ➔ Int
f. 4375457L ➔ Long
Q.7. List all the data types provided by Python language.
int long float complex
50 3682936L 4.3 5.78j
555 -0X5789L 56.28 .863j
-897 0231L -87.32 30+29J
-1976 0XDE567AFE -56.27e10 4.24e-8j
-936 -2467896435L 71.e19 45.j
Q.8. How will you distinguish list and tuple data types?
List - is like an array a= [1,2,3,4,5,6]
Tuple - But it is immutable. That means data in a tuple is write protected. Data in a tuple is
written using parenthesis and commas
Q.9. Differentiate between set and dictionary data type in Python.
Set is an unordered collection of unique items.
a = {15, 20, 13, 45, 67}
3. Q.10. Explain all the data types provided by Python language with appropriate
illustrations.
Number, String, List, Tuple, Set, Dictionary and File
Example for Dictionary:
dict2 = {'name': 'Smith', 'code': 1234, 'dept':'HR'}
Dictionary is an unordered collection of key value pairs.
The file data type is used in Python to store and work with files on the computer or on
the Internet.
Q.11. What is a slicing operator? How can you use it? Illustrate.
Python slicing is to extract part of string from your main string. This concept is called
unstring in COBOL.
Q.12. How can a user interact with the Python interpreter?
A). By typing ‘python’ on Linux, you can enter into python interpreter.
>>>
Q.13. Signify the role of input and output functions provided by Python language.
A). You can interact by using input() and print() functions. Input is to get input from user.
Print is for output.
14. How will you format the output in Python?
A). Output(), you can see many formats those you can use to display
● Print(‘ I am in output’, a)
● Print(‘I am {0} in output’.format(‘first’,’second’)
● Using format symbols
Q.15. Elaborate the significance of import command in Python with a suitable example.
A). The import command you can use to import your’.py’ module into python interpreter.