Top Python Interview Questions for Freshers 2020
These python interview questions for freshers 2020 will based on questions on python, python basic interview questions to make you prepare for your upcoming python interview programs. Practice here program questions in python with these most asked python interview questions and answers.
Top Python Basic Interview Questions and Answers 2020
- How to install Python on Windows and set path variable?
Ans: To install Python on Windows, follow the below steps:
Install python from this link: https://www.python.org/downloads/
After this, install it on your PC. Look for the location where PYTHON has been installed on your PC using the following command on your command prompt: cmd python.
Then go to advanced system settings and add a new variable and name it as PYTHON_NAME and paste the copied path.
Look for the path variable, select its value and select ‘edit’.
Add a semicolon towards the end of the value if it’s not present and then type %PYTHON_HOME%
- Mention the use of // operator in Python?
Ans: It is a Floor Division Operator , which is used for dividing two operands with the result as quotient showing only digits before the decimal point. For instance, 10//5 = 2 and 10.0//5.0 = 2.0.
- How can the ternary operators be used in python?
Ans: The Ternary operator is the operator that is used to show the conditional statements. This consists of the true or false values with a statement that has to be evaluated for it.
The Ternary operator will be given as:
[on_true] if [expression] else [on_false]x, y = 25, 50big = x if x < y else y
The expression gets evaluated like if x<y else y, in this case if x<y is true then the value is returned as big=x and if it is incorrect then big=y will be sent as a result.
- What is the purpose of ** operator?
Ans: ** Exponent − Performs exponential (power) calculation on operators. a**b = 10 to the power 20 if a = 10 and b = 20.
- What is the purpose of // operator?
Ans: // Floor Division − The division of operands where the result is the quotient in which the digits after the decimal point are removed.
- What is the purpose of is operator?
Ans: is − Evaluates to true if the variables on either side of the operator point to the same object and false otherwise. x is y, here is results in 1 if id(x) equals id(y).
- What is the purpose of not in operator?
Ans: not in − Evaluates to true if it does not finds a variable in the specified sequence and false otherwise. x not in y, here not in results in a 1 if x is not a member of sequence y.
- What are the two major loop statements?
Ans: for and while
- What is the purpose break statement in python?
Ans: break statement − Terminates the loop statement and transfers execution to the statement immediately following the loop.
- What is the purpose continue statement in python?
Ans: continue statement − Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
- What is lambda function in python?
Ans: ‘lambda’ is a keyword in python which creates an anonymous function. Lambda does not contain block of statements. It does not contain return statements.
- What is the usage of help() and dir() function in Python?
Ans: Ans: Help() and dir() both functions are accessible from the Python interpreter and used for viewing a consolidated dump of built-in functions.
Help() function: The help() function is used to display the documentation string and also facilitates you to see the help related to modules, keywords, attributes, etc.
Dir() function: The dir() function is used to display the defined symbols.
- What is the difference between remove() function and del statement?
Ans: You can use the remove() function to delete a specific object in the list.
If you want to delete an object at a specific location (index) in the list, you can either use del or pop.
- What is split() and join() functions in Python?
Ans: You can use split() function to split a string based on a delimiter to a list of strings.
You can use join() function to join a list of strings based on a delimiter to give a single string.
- What is map function in Python?
Ans: map function executes the function given as the first argument on all the elements of the iterable given as the second argument. If the function given takes in more than 1 arguments, then many iterables are given. #Follow the link to know more similar functions.
- What are docstrings in Python?
Ans: Docstrings are not actually comments, but, they are documentation strings. These docstrings are within triple quotes. They are not assigned to any variable and therefore, at times, serve the purpose of comments as well.
- Mention the use of the split function in Python?
Ans: The use of the split function in Python is that it breaks a string into shorter strings using the defined separator. It gives a list of all words present in the string.
- What are tuples in Python?
Ans: A tuple is another sequence data type that is similar to the list. A tuple consists of a number of values separated by commas. Unlike lists, however, tuples are enclosed within parentheses.
- What is the difference between tuples and lists in Python?
Ans: The main differences between lists and tuples are − Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. Tuples can be thought of as read-only lists.
- What is zip() function in Python?
Ans: Python zip() function returns a zip object, which maps a similar index of multiple containers. It takes an iterable, convert into iterator and aggregates the elements based on iterables passed. It returns an iterator of tuples.