Python Interview Questions
What is the difference between list and tuple?
List:
1. List is created by using [ ] symbol.
2. List elements are mutable.
Example: a = [10, 20, 30]
Tuple:
1. Tuple is created by using ( ) symbol.
2. Tuple elements are immutable.
Example: b = (100, 200, 300)
What is set?
Set is created by using { } symbol.
Set stores elements in random order and doesn’t allow duplicate elements.
Example: c = {‘palle’, ‘python’, ‘bangalore’}
What is a dictionary?
Dictionary is used to store key-value pairs. Keys should be unique, and values can be
duplicates.
Example: d = {'email': 'enquiry@[Link]', 'pw': 'abcd123', 'course': 'python',
'duration': 90}
How will you create an array in Python?
We can create an array in Python by importing the array module.
Example:
import array
e = [Link]('i', [10, 20, 30, 40])
print(e)
What is the difference between array and list?
Array:
1. In an array, we can store only homogeneous elements.
List:
1. In a list, we can store both homogeneous and heterogeneous elements.