Important interview questions in python
We already discussed python and its fundamentals. Now, we move ahead to what our expected questions are asked by top MNC’s like Google, Facebook, and so on. These questions are followed by what we saw in previous blogs. This blog includes both Theory and practical questions, scroll down for practical questions.
Theory Questions
Q1. What is Python?
- Python is an Interpreter, a High-level, Interactive, and reliable Programming language was developed by Guido Van Rossum. it was released in the year 1991.
- It is a general-purpose programming language and also an object-oriented language.
Q2. what are the disadvantage of Python?
- Python is an interpreter language, so it is slow as compared to C/C++. Python is not good for those who develop a high-graphics-3D game.
- Python is slower than C/C++ when it comes to the computation of heavy tasks and desktop applications.
Q3. What about comments in Python?
- In Python, comments begin with a hash symbol (#).
- The lines that begin with # are considered as comments and ignored by the Python interpreter. Comments may be single-line or no multi-lines
- Example:
- #Iterathon Blog
- ”’ It is a multiline comment which contains more than one line ”’
Q4. what is an indentation and why it is used?
- In Python, Indentation is Whitespaces or tabs to separate blocks.
- In other languages like C, C++, java use curly braces { } to indicate blocks of codes for class, functions, or body of the loops and block of selection command. But in python, there are no curly braces for indicating blocks instead of curly braces.
Q5. What are Control structures and their types?
- A program statement that causes a jump of control from one part of the program to another based on conditions is called a control structure or control statement. In Python, There are three important control structures,
- Sequential
- Alternating or Conditional Branching
- Iteration or Looping
Q6. What is a membership operator in Python?
- Python provides two membership operators, This operator is used to check the given value is present or not in searching values. It returns the values in True or False.
- in
- not in
Q7. what about Jump statements and their types?
- A jump statement is used to transfer the control from one part of a program to another part. In Python, There are three types of Jump statements.
- break
- continue
- pass
Q8. What is the use of a pass statement in python?
- pass statement in Python programming is a null statement. pass statement when executed by the interpreter it is completely ignored. Nothing happens when the pass is executed. pass is generally called a placeholder.
Q9. Define data types in python.
- Variables can store the values in different forms for interpreters to understand easily. There are different data types in python.
- string
- list
- tuple
- set
- dictionary
- boolean
- int
- float
- complex
Q10. What is slicing in python?
- A slice is a substring of the main string. A substring can be taken from the original string by using [ ] operator and index or subscript values. Thus, [ ] is also known as the slicing operator.
- Example:
- >>>blog = “Iterathon”
- >>>blog[0:5]
- >>>’Iter‘
Q11. What is the relational between String and Tuple?
- Both string and Tuple are immutable (unchangeable).
- Strings
- In Python, a string literal is a sequence of characters surrounded by quotes. Python supports single, double, and triple quotes for a string.
- A character literal is a single character surrounded by single or double quotes. The value with triple-quote “‘ ‘” is used to give multi-line string literal.
- Example
- “Single Line Strings”
- “‘ This is for multiline strings “‘
- Tuple
- Tuples consist of a number of values separated by a comma and enclosed within parentheses(). A tuple is similar to a list, values in a list can be changed but not in a tuple.
Q12. Define Set in python.
- A set is another type of collection data type. A Set is a mutable and unordered collection of elements without duplicates. That means the elements within a set cannot be repeated.
- A set is created by placing all the elements separated by a comma within a pair of curly brackets { }.
Q13. Define Dictionary in Python.
- A dictionary is a mixed collection of elements. Unlike other collection data types such as a list or tuple, the dictionary type stores a key along with its element. It also a mutable data type.
- The keys in a Python dictionary are separated by a colon ( : ) while the commas work as a separator for the elements. The key-value pairs are enclosed with curly braces { }.
Practical Questions
Q1. Write a Python program to exchange the values of two numbers without using a temporary variable.
a = int(input("Enter your first number"))
b = int(input("Enter your Second number"))
a,b = b,a
print("a is ",a, "b is ",b)
Q2. Write a python program to find the max of two numbers.
num1 = int(input("First number"))
num2 = int(input("Second number"))
if num2 >= num1:
largest = num2
else:
largest = num1
print("Largest number is", largest)
Q3. Write a python program for sum of given numbers
num = input("Enter a number, you want to sum")
sum = 0
for char in num:
sum = sum + int(char)
print(sum)
Q4. Write a Python program to reverse the string
str = input("Enter the string to reverse")
for i in str[::-1]:
print(i,end='')
Q5. Write a Python Program to reverse a word
website = "www.iterathon.tech"
separate = website.split('.')
separate.reverse()
rev = '.'.join(separate)
print(rev)
Q6. Calculates a Simple interest using python
principle = int(input("Money you borrowed: "))
interest_rate = float(input("Interest Rate: "))
time = float(input("Duration:"))
#Calculates simple interest
simple_interest = principle * (interest_rate/100) * time
print("Simple interest is:", simple_interest)
Q7. Write a Python program to remove a element 11 from the list 12,7,6,18,23,14,6,7,10,11,5.
list=[12,7,6,18,23,14,6,7,10,11,5]
list.remove(11)
print(list)
Q8. Write a Python program to remove duplicates from a list.
count=int(input("Enter the no of elements you enter"))
list1=[]
for i in range(count):
list1.append(int(input("enter the elements")))
set1=set(list1)
print(list(set1))
Q9. Write a program to insert a value in a list at the specified location.
# My list
ist1=[1,2,3]
# insert a element 4 in 0th position
list1.insert(0,4)
print(list1)
Q10. Write an example program for symmetric difference in python.
SET_A = {‘A’,2,3} SET_B = {1,2,3} print(SET_A.symmetric_difference(SET_B))
Q11. Write a python program to find all keys in dictionary
Dict = {‘name’:’Iterathon’, ‘subject’:’Blog’} print(Dict.keys())
Q12. write an example python program for slicing an element.
blog = "Iterathon" #Iter print(blog[0:5]) #thon print(blog[5:])
My Previous Post
What is dictionary: https://iterathon.tech//what-is-dictionary-in-python-with-examples/
LEARN LITTLE BY LITTLE TO CHANGE THE TECH WORLD