Detailed Python Core Concepts Notes for Interviews (LSEG-Focused)
🔹 PART 1: VARIABLES, DATA TYPES, OPERATORS
Variables & Data Types
• No explicit declaration needed (Python is dynamically typed)
• Common types: int , float , str , bool , list , tuple , set , dict
• Type conversion: int() , float() , str()
• input() for user input, returns string by default
Operators
• Arithmetic: + , - , * , / , // , % , **
• Comparison: == , != , > , < , >= , <=
• Logical: and , or , not
• Membership: in , not in
🔹 PART 2: CONDITIONALS & LOOPS
Conditional Statements
if condition:
...
elif condition:
...
else:
...
Loops
• for loops: Iterates over sequences
• while loops: Repeats until condition is false
• break , continue , pass
1
🔹 PART 3: FUNCTIONS
Function Basics
def function_name(parameters):
return result
• Default arguments: def greet(name, lang='English')
• *args : Variable positional args (tuple)
• **kwargs : Variable keyword args (dict)
Lambda Functions
square = lambda x: x * x
Used with map() , filter() , sorted()
🔹 PART 4: PYTHON DATA STRUCTURES
List
• Mutable, ordered, allows duplicates
lst = [1, 2, 3]
lst.append(4)
lst[0]
Tuple
• Immutable, ordered
tpl = (1, 2)
tpl[1]
Set
• Unordered, no duplicates
2
s = {1, 2, 3}
s.add(4)
Dictionary
• Key-value pairs
d = {"a": 1, "b": 2}
d["a"]
🔹 PART 5: STACK, QUEUE, LINKEDLIST, HEAP
Stack (LIFO)
stack = []
stack.append(1)
stack.pop()
Queue (FIFO)
from collections import deque
queue = deque()
queue.append('A')
queue.popleft()
Linked List (Singly)
class Node:
def __init__(self, data):
self.data = data
self.next = None
3
Heap
import heapq
heapq.heapify(list)
heapq.heappop()
🔹 PART 6: ENUMERATE, ZIP, MAP, FILTER, SORTED
• enumerate() returns (index, value)
• zip() combines two lists
• map(func, iterable) applies function
• filter(func, iterable) filters elements
• sorted(list, key=lambda) sorts with logic
🔹 PART 7: OOPS IN PYTHON
4 Pillars
1. Encapsulation
• Hide data with private variables ( __var )
• Access via methods
2. Abstraction
• Hide implementation details
• Use abc module and @abstractmethod
3. Inheritance
• One class inherits from another
class A:
...
class B(A):
...
4. Polymorphism
• Same function behaves differently
• Method overriding and duck typing
4
Special Methods
• __init__ : Constructor, runs on object creation
• __str__ : Defines print behavior of object
🔹 PART 8: FILE HANDLING
with open("file.txt", "r") as f:
data = f.read()
Modes: 'r' , 'w' , 'a' , 'x' , 'b'
Write
with open("file.txt", "w") as f:
f.write("Hello")
Read line by line
for line in f:
print(line.strip())
🔹 PART 9: EXCEPTION HANDLING
try:
...
except ValueError:
...
finally:
...
• try , except , finally
• Custom exceptions using class inheritance from Exception
5
🔹 PART 10: MODULES
• Use import module_name
• Built-ins: math , random , datetime , os , sys
• Custom module: Create .py file and import
End of Core Python Notes
Next: NumPy, Pandas, Matplotlib, and Machine Learning