Python Interview Questions PDF
Python Interview Questions PDF
1. https://intellipaat.com/interview-question/python-interview-
questions/
2. https://www.testingbrain.com/interview/python-interview-
questions.html
3. https://www.sanfoundry.com/python-interview-questions-
answers-freshers/
4. https://www.tutorialspoint.com/python/python_mock_test.html
The difference between list and tuple is that list is mutable while tuple is not.
Tuple can be hashed for e.g as a key for dictionaries.
Everything in Python is an object and all variables hold references to the objects.
The references values are according to the functions; as a result you cannot
change the value of the references. However, you can change the objects if it is
mutable.
List
Sets
Dictionaries
Strings
Tuples
Numbers7
A lambda form in python does not have statements as it is used to make new
function object and then return them at runtime.
A mechanism to select a range of items from sequence types like list, tuple, strings
etc. is known as slicing.
Python sequences can be index in positive and negative numbers. For positive
index, 0 is the first index, 1 is the second index and so forth. For negative index, (-1)
is the last index and (-2) is the second last index and so forth.
12) Mention what are the rules for local and global variables in Python?
Local variables: If a variable is assigned a new value anywhere within the function's
body, it's assumed to be local.
Global variables: Those variables that are only referenced inside a function are
implicitly global.
Python comprises of a huge standard library for most Internet platforms like
Email, HTML, etc.
Python does not require explicit memory management as the interpreter itself
allocates the memory to new variables and free them automatically
Provide easy readability due to use of square brackets
Easy-to-learn for beginners
Having the built-in data types saves programming time and effort from
declaring variables
They are mutable and hence will not change. The values associated with the keys can
be of any Python types.
17). How do you invoke the Python interpreter for interactive use?
python or pythonx.y where x.y are the version of the Python interpreter desire
try:
….#This can be any code
except:
…# error handling code goes here
finally.
…# code that will be executed regardless of exception handling goes here.
Q20. Q10. What happens if an error occurs that is not handled in the except block?
The program tenuinates. and an execution trace is sent to sys.stderr.
Q27. Use a for loop and illustrate how you would define and print the characters in a string
out, one per line.
myString = “I Love Python”
for myChar hi myString:
print myChar
Q28. Given the string “I LoveQPython” use afor loop and illustrate printing each character tip
to, but not including the Q.
inyString = “I Love Pijtlzon”
for myCizar in myString:
fmyC’har ==
break
print myChar
Answer:
The major difference is tuples are immutable while a list is mutable. It
means once you create tuple you cannot edit or make changes in the
value in tuple while in a list we can edit the value in it.
Tuples List
A tuple is a sequence of immutable objects List are versatile datatype which are Mutable
The syntax for Tuples are shown by parenthesis {} Syntax for List is shown by square brackets []
Q30. What does the split(), sub() and subn() methods do?
Answer:
Split() :its uses a regex pattern to split any given string into a created list.
Sub() : It will find all the substring where this regex pattern will match and
then replace the string.
Subn() : It is similar to a sub(), it will return the new string along with the
other no. of replacements.
Q31. Mention the way to display the text contents of the files in the
reverse order?
Answer:
First, convert the file into the list and after that reverse this list by utilizing
reversed ().
Answer:
append() adds the element at the end.
extend() adds the elements of a different list at the end.