Python Interviews
Quick Python Cheat Sheet for Beginners πβοΈ
Python is widely used for data analysis, automation, and AIβperfect for beginners starting their coding journey.
Aggregation Functions π
β’ sum(list) β Adds all values
π sum([1,2,3]) = 6
β’ len(list) β Counts total elements
π len([1,2,3]) = 3
β’ max(list) β Highest value
π max([4,7,2]) = 7
β’ min(list) β Lowest value
π min([4,7,2]) = 2
β’ sum(list)/len(list) β Average
π sum([10,20])/2 = 15
Lookup / Searching π
β’ in β Check existence
π 5 in [1,2,5] = True
β’ list.index(value) β Position of value
π [10,20,30].index(20) = 1
β’ Dictionary lookup
π data = {"name": "John", "age": 25} data["name"] # John
Logical Operations π§
β’ if condition: β Decision making
π if x > 10: print("High") else: print("Low")
β’ and β All conditions true
β’ or β Any condition true
β’ not β Reverse condition
Text (String) Functions π€
β’ len(text) β Length
π len("hello") = 5
β’ text.lower() β Lowercase
β’ text.upper() β Uppercase
β’ text.strip() β Remove spaces
π " hi ".strip() = "hi"
β’ text.replace(old, new)
π "hi".replace("h","H") = "Hi"
β’ String concatenation
π "Hello " + "World"
Date Time Functions π
β’ from datetime import datetime
β’ datetime.now() β Current date time
β’ Extract values:
now = datetime.now() now.year now.month now.day
Math Functions β
β’ import math
β’ math.sqrt(x) β Square root
β’ math.ceil(x) β Round up
β’ math.floor(x) β Round down
β’ abs(x) β Absolute value
Conditional Aggregation (Like Excel SUMIF) β‘
β’ Using list comprehension
nums = [10, 20, 30, 40] sum(x for x in nums if x > 20) # 70
β’ Count condition
len([x for x in nums if x > 20]) # 2
Pro Tip for Data Analysts π‘
π For real-world work, use libraries: pandas & numpy
Example:
import pandas as pd df["salary"].mean()
Python Resources: https://whatsapp.com/channel/0029VaiM08SDuMRaGKd9Wv0L
Double Tap β₯οΈ For More
1.2K Β·