12 Tricky Python Coding Interview Questions

Among the leading computer programming languages, Python takes the first place. In this post, I am sharing the 12 Python frequently asked Coding Interview Questions on the basics of Python Language.


Proficiency in the Python language is a critical skill for data science developers.

To write a code as a technical resource, he or she must be strong in basics. To prove your skills in interviews, you should be in a position to answer this level of questions.


Python Top Interview Questions

1). Why Python is different from other languages of 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.

Print ("Hello")
Print ("World")

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.

See from left, Down, UP, Down, UP- approach

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
Result: Srinimf

Python Debugging Tools


python debugging tools

References


7). How to accept user Input in Python?

You need to use input parameter.

newInput = input("abcdefghijk")
print(newInput)
Result: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
else :
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?

OperationDescription
substring in sReturns 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 define data types of int or float 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

References

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.