- Difference between
intandfloat? | Feature |int|float| | ---------- | ---------------- | ---------------------------- | | Stores | Whole numbers | Decimal numbers | | Example |10,-5|10.5,-3.14| | Precision | Exact | Approximate (floating point) | | Memory | Less | More | | Operations | Faster | Slightly slower | | Conversion |int(5.9)→5|float(5)→5.0|
Key point: int has no decimal part, float always has decimal precision.
-
What is implicit vs explicit type conversion?
🔹 Implicit (Automatic)
Python automatically converts one type to another. a = 10 # int b = 2.5 # float c = a + b # Python converts int → float print(c) # 12.5
✔ Done by Python ✔ No data loss usually
🔹 Explicit (Manual)
The programmer converts type manually.
x = "100" y = int(x) print(y) # 100
✔ Done by developer ✔ Used when types mismatch
-
How does Python handle integer overflow? Python DOES NOT overflow integers. It supports arbitrary-precision integers.
x = 10**100 print(x)
✔ No limit on size ✔ Memory increases dynamically ✔ Slower for extremely large numbers Unlike C/Java: No wrap-around or overflow error.
-
What is truthy and falsy in Python? 🔹 Falsy values
Evaluated as False in condition:
False 0 0.0 '' [] {} () None
Example:
if []: print("True") else: print("False") # Executes
🔹 Truthy values
Everything else is truthy:
1 "hello" [1,2] {'a':1}
-
Difference between
==andis? == Compares values is Compares memory location (identity)
- Convert float
12.9to int. What happens? - Convert string
"123"to integer safely. - Reverse a string without using slicing.
- Count vowels in a string.
- Check if a number is palindrome.
- Convert list of chars to string.
- Convert string to list of words.
- Difference between
join()andsplit()? - Convert
"True"to boolean – is it possible? - Remove duplicates from string.
- Print each character using loop.
- Find frequency of each character.
- Reverse words in a sentence.
- Print only digits from string.
- Find longest word in sentence.
- Difference between list and tuple.
- What is shallow vs deep copy?
- Time complexity of append, pop?
- Difference between
extend()andappend()? - When to use list comprehension?
- Print even numbers from list.
- Reverse list using loop.
- Find second largest number.
- Remove duplicates using loop.
- Count frequency of elements.
- Convert list → tuple.
- Convert list → set.
- Convert list of strings → list of ints.
- Convert nested list to flat list.
- Convert list to dictionary.
- Why tuples are immutable?
- Convert tuple → list.
- Find index of element.
- Loop through tuple.
- Swap values using tuple unpacking.
- Count occurrences of element.
- Convert tuple of pairs → dict.
- Remove duplicates from tuple.
- Sort tuple.
- Difference between
(1)and(1,)?
- Difference between set and list.
- Why set doesn’t allow duplicates?
- Convert list → set.
- Find union, intersection, difference.
- Loop through set.
- Check subset and superset.
- Remove elements safely.
- Convert set → list.
- Find common elements between 2 lists.
- When to use frozenset?
- Difference between dict and OrderedDict.
- Keys rules in dictionary.
- Can list be key? Why?
- Difference between get() and [].
- How to merge two dicts?
- Loop keys only.
- Loop values only.
- Loop key-value pairs.
- Find max value key.
- Count word frequency using dict.
- Convert list of tuples → dict.
- Convert dict → list of keys.
- Convert dict → list of values.
- Convert dict → tuple.
- Sort dictionary by values.
- Difference between for & while.
- What is infinite loop?
- Use of break & continue.
- Print numbers 1–100.
- Print prime numbers.
- Fibonacci series.
- Factorial using loop.
- Nested loops example.
- Pattern printing.
- Reverse number using loop.
- int → float
- float → int
- str → int (safe way)
- list → tuple
- tuple → list
- list → set
- set → list
- dict → list
- list → dict
- bool → int
- Flatten nested list.
- Remove duplicate dictionaries.
- Sort list of tuples.
- Group anagrams.
- Convert list of dicts → single dict.
- Find common keys in dicts.
- Merge lists without duplicates.
- Count elements in nested list.
- Find max value in dict of lists.
- Reverse dictionary.
- Check if list is sorted.
- Rotate list k times.
- Find missing number.
- Find duplicate number.
- Two sum problem.
- Intersection of 3 lists.
- Find pairs with sum.
- Convert Roman → integer.
- String compression.
- Balanced parentheses.
- What is output of:
print(bool("False"))a = [1,2,3]
b = a
b.append(4)
print(a)print(type({}))print(set([1,1,2,2]))print(1 == True)- Read CSV → dict.
- Parse JSON → Python object.
- Remove null values from list.
- Count API response status codes.
- Convert input string → number safely.
- Difference between mutable & immutable?
- Memory behavior of lists vs tuples.
- When to use set vs dict?
- Time complexity of searching in list vs set.
- Why dict lookup is fast?