0% found this document useful (0 votes)
2 views

Python Interview Questions

The document outlines key differences between Python data structures: lists are mutable and created with [ ], while tuples are immutable and created with ( ). It also describes sets, which are unordered collections of unique elements created with { }, and dictionaries that store key-value pairs with unique keys. Additionally, it explains how to create arrays using the array module, highlighting that arrays can only store homogeneous elements, unlike lists which can store heterogeneous elements.

Uploaded by

ishajasminen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python Interview Questions

The document outlines key differences between Python data structures: lists are mutable and created with [ ], while tuples are immutable and created with ( ). It also describes sets, which are unordered collections of unique elements created with { }, and dictionaries that store key-value pairs with unique keys. Additionally, it explains how to create arrays using the array module, highlighting that arrays can only store homogeneous elements, unlike lists which can store heterogeneous elements.

Uploaded by

ishajasminen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

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': '[email protected]', '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 = array.array('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.

You might also like