Python is the leading programming language. Below, you will find 12 frequently asked Python coding interview questions.
Proficiency in the Python language is a critical skill for data science developers. To write code as a technical resource, one must be strong in basics. To prove your skills in interviews, you should answer o this level of questions.
12 Python tough interview questions
1. Why is Python different from other languages such as Java, C, C++?
Basically, Python is an interpreted language. So, the Python code will execute dynamically. Compilation of Python program not required.
2. How to give Comments in Python code?
The first letter should be ‘#’. This works as commented line in Python.
3. What is indention in Python? and why this is important?
Python supports indentation. Like COBOL, if you remember, there are indentation rules that ‘IF” statement should start from 12th position.
Both the ‘Print’ statements not in the same Column. So Python gives an error during execution.
4. What is Variable concept in Python?
In Python, you can just assign the value to a variable dynamically. For example, “myTown = 201”, now if you print(myTown), you will get 201.
To define a variable, Python follows some rules.
Cannot start variable names with numbers.
5). What are the top Number Data types in Python?
Those are “int”, “float”.
6). What is Concatenation technique in Python?
You can use “+”. Check the below example:
firstName = "Srini"
lastName = "mf"
name = firstName + lastName
7. How to accept user Input in Python?
You need to use input parameter.
newInput = input("abcdefghijk")
8. Why Colon (“:”) is required in IF statement?
To give statements after the IF, the colon is mandatory.
IF sale > 100 :
sale = sale + 20
sale = sale - 20
9. What is the difference between Assign and Equal?
If you give single = , that is called assign.
If you give ==, that is called equal.
10. What are the top String handling methods in Python?
|substring in s||Returns True if the string s contains substring and False otherwise.|
|s.count(substring)||Returns the number of non-overlapping occurrences of substring in the string s.|
|s.endswith(substring)||Returns True if the string s ends with the substring and False otherwise.|
|s.find(substring)||Returns the lowest index in the string s where substring begins, or −1 if substring is not found.|
|s.startswith(substring)||Returns True if the string s begins with substringand False otherwise.|
11. What are the top Looping Techniques in Python?
Those are “FOR” and “WHILE”
12. Do we need to declare int or float data types before hand?
Nope, We can dynamically assigns the data type.
total = 0.0 count = 0 inputStr = input("Enter value: ") while inputStr != "" : value = float(inputStr) total = total + value count = count + 1 inputStr = input("Enter value: ") if count > 0 : average = total / count else : average = 0.0
- FAQ Python.org
- How to debug using pudb tool
- How to debug using pdb tool
- How to debug using ipdb tool
You must be logged in to post a comment.