Below is a comprehensive Python technical test revision guide covering:
- Variables & Data Types
- Conditionals
- Loops (for / while)
- Functions
- Strings
- Lists, Tuples, Sets
- Dictionaries
- List Comprehensions
- Error Handling
- File Handling
- Object-Oriented Programming
- Common Interview Logic Problems
- Recursion
- Sorting & Searching
- Basic Algorithm Patterns
- Generators
- Decorators
- Lambda Functions
- Working with Dates
- Basic Data Handling (pandas-style logic without external dependency focus)
This is intentionally long and structured like a self-study handbook you can review before the interview.
1️⃣ Variables and Data Types
Python is dynamically typed.
# Integer
x = 10
# Float
y = 3.14
# String
name = "John"
# Boolean
is_active = True
# None
value = None
Type Checking
print(type(x)) # <class 'int'>
print(isinstance(x, int)) # True
2️⃣ Conditional Statements
Basic If-Else
age = 18
if age >= 18:
print("Adult")
else:
print("Minor")
If-Elif-Else
score = 75
if score >= 90:
grade = "A"
elif score >= 70:
grade = "B"
elif score >= 50:
grade = "C"
else:
grade = "Fail"
print(grade)
Ternary Operator
result = "Pass" if score >= 50 else "Fail"
3️⃣ For Loops
Basic Loop
for i in range(5):
print(i)
Loop Through List
numbers = [10, 20, 30]
for num in numbers:
print(num)
Loop With Index
for index, value in enumerate(numbers):
print(index, value)
Nested Loop
for i in range(3):
for j in range(2):
print(f"i={i}, j={j}")
4️⃣ While Loops
count = 0
while count < 5:
print(count)
count += 1
Break and Continue
for i in range(10):
if i == 5:
break
print(i)
for i in range(10):
if i % 2 == 0:
continue
print(i)
5️⃣ Functions
Basic Function
def greet(name):
return f"Hello {name}"
print(greet("Alice"))
Default Parameters
def power(base, exponent=2):
return base ** exponent
print(power(3)) # 9
print(power(3, 3)) # 27
Variable Arguments
def add_numbers(*args):
return sum(args)
print(add_numbers(1, 2, 3, 4))
Keyword Arguments
def print_details(**kwargs):
for key, value in kwargs.items():
print(key, value)
print_details(name="John", age=30)
6️⃣ Strings
Basic Operations
text = "Python"
print(text.lower())
print(text.upper())
print(text[0])
print(text[-1])
String Slicing
print(text[0:3]) # Pyt
print(text[::-1]) # nohtyP
String Methods
sentence = "hello world"
print(sentence.replace("world", "Python"))
print(sentence.split())
print(" ".join(["Hello", "World"]))
Check Palindrome
def is_palindrome(s):
s = s.lower().replace(" ", "")
return s == s[::-1]
print(is_palindrome("Race car"))
7️⃣ Lists
numbers = [1, 2, 3]
numbers.append(4)
numbers.remove(2)
List Comprehension
squares = [x**2 for x in range(10)]
Filter Even Numbers
evens = [x for x in range(20) if x % 2 == 0]
Find Maximum
numbers = [4, 8, 1, 9]
maximum = numbers[0]
for num in numbers:
if num > maximum:
maximum = num
print(maximum)
8️⃣ Tuples
point = (10, 20)
x, y = point
print(x, y)
9️⃣ Sets
numbers = {1, 2, 3, 3}
print(numbers) # duplicates removed
a = {1, 2, 3}
b = {3, 4, 5}
print(a.union(b))
print(a.intersection(b))
🔟 Dictionaries
person = {
"name": "Alice",
"age": 30
}
print(person["name"])
Loop Through Dictionary
for key, value in person.items():
print(key, value)
Count Character Frequency
def char_count(text):
counts = {}
for char in text:
counts[char] = counts.get(char, 0) + 1
return counts
print(char_count("hello"))
1️⃣1️⃣ Error Handling
try:
x = int("abc")
except ValueError:
print("Invalid conversion")
finally:
print("Done")
1️⃣2️⃣ File Handling
Write to File
with open("data.txt", "w") as file:
file.write("Hello World")
Read from File
with open("data.txt", "r") as file:
content = file.read()
print(content)
1️⃣3️⃣ Object-Oriented Programming (OOP)
Basic Class
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def greet(self):
return f"My name is {self.name}"
person1 = Person("Alice", 25)
print(person1.greet())
Inheritance
class Employee(Person):
def __init__(self, name, age, salary):
super().__init__(name, age)
self.salary = salary
def get_salary(self):
return self.salary
emp = Employee("Bob", 30, 50000)
print(emp.get_salary())
1️⃣4️⃣ Recursion
Factorial
def factorial(n):
if n == 0:
return 1
return n * factorial(n - 1)
print(factorial(5))
Fibonacci
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
1️⃣5️⃣ Sorting
Built-in Sort
numbers = [5, 2, 9, 1]
numbers.sort()
Custom Sort
students = [
{"name": "Alice", "age": 25},
{"name": "Bob", "age": 20}
]
students.sort(key=lambda x: x["age"])
1️⃣6️⃣ Searching
Linear Search
def linear_search(lst, target):
for index, value in enumerate(lst):
if value == target:
return index
return -1
Binary Search
def binary_search(lst, target):
left = 0
right = len(lst) - 1
while left <= right:
mid = (left + right) // 2
if lst[mid] == target:
return mid
elif lst[mid] < target:
left = mid + 1
else:
right = mid - 1
return -1
1️⃣7️⃣ Common Interview Logic Problems
Reverse a Number
def reverse_number(n):
return int(str(n)[::-1])
Find Duplicate in List
def find_duplicates(lst):
seen = set()
duplicates = set()
for num in lst:
if num in seen:
duplicates.add(num)
seen.add(num)
return list(duplicates)
Two Sum Problem
def two_sum(nums, target):
lookup = {}
for i, num in enumerate(nums):
complement = target - num
if complement in lookup:
return [lookup[complement], i]
lookup[num] = i
1️⃣8️⃣ Generators
def count_up_to(n):
i = 1
while i <= n:
yield i
i += 1
for num in count_up_to(5):
print(num)
1️⃣9️⃣ Decorators
def logger(func):
def wrapper():
print("Function started")
func()
print("Function ended")
return wrapper
@logger
def say_hello():
print("Hello")
say_hello()
2️⃣0️⃣ Working with Dates
from datetime import datetime
now = datetime.now()
print(now.year)
date_string = "2025-01-01"
date_obj = datetime.strptime(date_string, "%Y-%m-%d")
2️⃣1️⃣ Practical Data Logic Example (Interview Style)
Group Items by Category
data = [
{"name": "Item1", "category": "A"},
{"name": "Item2", "category": "B"},
{"name": "Item3", "category": "A"}
]
grouped = {}
for item in data:
category = item["category"]
if category not in grouped:
grouped[category] = []
grouped[category].append(item)
print(grouped)
2️⃣2️⃣ Performance Awareness
Time Complexity Awareness
- O(1) → Constant
- O(n) → Linear
- O(log n) → Binary Search
- O(n²) → Nested loops
Example:
# O(n²)
for i in range(n):
for j in range(n):
pass
2️⃣3️⃣ Clean Code Tips for Technical Tests
- Use meaningful variable names
- Handle edge cases
- Avoid unnecessary nested loops
- Consider time complexity
- Use built-in functions when appropriate
- Add short comments explaining logic
Final Interview Advice (Important)
In technical tests:
- Speak your thought process out loud
- Clarify edge cases
- Write a simple solution first
- Then optimize if needed
- Test with sample input
you may also get:
- Data transformation problems
- Aggregation logic
- Filtering structured data
- Working with dictionaries and lists heavily