Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Python 10 questions

Data Types and Data Structures

Understand primitive data types and structures in Python, including lists, tuples, dictionaries, sets, and custom collection objects.

More Python
Interview questions 1–10 of 10
1

What is the difference between a list and a tuple in Python? - Data Types and Data Structures

FeatureListTupleSyntax[1, 2, 3](1, 2, 3)MutabilityMutableImmutableSpeedSlowerFasterMemoryMoreLessDict KeyNoYes...

Read answer →
2

How do you remove duplicates from a list while preserving order? - Data Types and Data Structures

my_list = [1, 2, 2, 3, 1, 4, 2, 5] # Method 1: dict.fromkeys() - BEST for Python 3.7+ result = list(dict.from...

Read answer →
3

What is the difference between a list and a set in Python? - Data Types and Data Structures

FeatureListSetOrderedYesNoDuplicatesAllowedNoIndexingYesNoMembership O(n/1)O(n)O(1)my_list = [1, 2, 3, 2, 1]...

Read answer →
4

What is a dictionary comprehension? - Data Types and Data Structures

squares = {x: x**2 for x in range(5)} print(squares) # {0: 0, 1: 1, 2: 4, 3: 9, 4: 16} # With condition even...

Read answer →
5

How does a Python dictionary work internally? - Data Types and Data Structures

# Hash function hash('key') # Returns hash value hash('hello') # 8730470218056277053 # O(1) lookup my_dict...

Read answer →
6

What is the difference between shallow copy and deep copy? - Data Types and Data Structures

import copy # Shallow copy - copies only surface level original = [[1, 2], [3, 4]] shallow = copy.copy(origin...

Read answer →
7

What is the difference between append() and extend()? - Data Types and Data Structures

my_list = [1, 2] # append() - adds whole object as single element my_list.append([3, 4]) print(my_list) # [1...

Read answer →
8

How do you sort a dictionary by its values? - Data Types and Data Structures

my_dict = {'apple': 5, 'banana': 2, 'cherry': 8, 'date': 3} # Sort by values (ascending) sorted_dict = dict(s...

Read answer →
9

What are Python sets used for and how are they different from lists? - Data Types and Data Structures

# Sets store unique elements my_set = {1, 2, 3, 2, 1} # Duplicates removed print(my_set) # {1, 2, 3} # No i...

Read answer →
10

What is the difference between mutable and immutable data types? - Data Types and Data Structures

TypeMutableImmutableExampleslist, dict, setint, str, tuple, frozensetChange in placeYesNoDict keyNoYesPerforma...

Read answer →