A 101-103 Siddhivinayak Towers, Off S.G. Highway, Ahmedabad, Gujarat 380051

# Python Interview Questions – Part 2

/ /

## 1. What is the difference between lists and tuples?

• Lists :
• Lists are mutable.
• Lists contains squared brackets- []
• list1 = list(1,2,3,4) #[1,2,3,4]
• Tuples :
• Tuples are immutable.
• Tuples contains round brackets – ()
• tup1 = tuple(1,2,3,4) #(1,2,3,4)

## 2. How will you check that all characters in a string are digits ?

• isdigit() function is used to check for digits in a string. It returns True if the string contains digits only or False otherwise.

## 3. What is the output for [‘Hi!’] * 4 ?

• [‘Hi!’,‘Hi!,’‘Hi!’,‘Hi!’]

## 4. Can we change or update the keys from the dictionaries ?

• Keys are immutable i.e they cannot be updated. Only the values of the dictionaries can be changed. If you want to change the keys you can add a new key value pair with the updated key.

## 5. What are OOPs concepts in Python?

• Inheritance
• Polymorphism
• Data Abstraction
• Encapsulation

## 6. What is the output of the following program?

a = 4.5
b = 2
print a//b

Ans. 2.0
Note : Using ‘//’ we can get the remainder in Python

## 7. What is the output of the following program?

a=[1,2,3,4,5,6,7,8,9]
print(a[::2])
Ans. [1,3,5,7,9]

i = 0
while i < 3:
print(i)
i += 1
else:
print(0)

Ans. 0 1 2 0

## 9. What is the output of the following program?

init_tuple_a = ‘a’, ‘b’
init_tuple_b = (‘a’, ‘b’)
print (init_tuple_a == init_tuple_b)
Hint : True or False

Ans. True

Posted on / Categories Blogs