Skip to content

Latest commit

 

History

History
172 lines (132 loc) · 2.6 KB

File metadata and controls

172 lines (132 loc) · 2.6 KB

🐍 Python Fun Facts Collection

A curated list of beginner‑friendly and interesting Python fun facts, collected during daily practice sessions.


1️⃣ Python doesn’t need semicolons

Python uses newlines to end statements.

x = 10
print(x)

Semicolons can be used, but they’re not Pythonic.


2️⃣ Booleans are numbers in Python

bool is a subclass of int.

True + True   # 2
False + 5     # 5

3️⃣ None is not equal to 0 or False

None == 0      # False
None == False  # False

None means no value, not zero.


4️⃣ Strings can be multiplied

"Hi " * 3

Output:

Hi Hi Hi

5️⃣ Slicing works the same for lists & strings

name = "Asma"
nums = [1,2,3,4]

name[::-1]  # 'amsA'
nums[::-1]  # [4,3,2,1]

6️⃣ Python integers have unlimited precision

x = 10**200
print(x)

Python can handle very large numbers without overflow.


7️⃣ Underscores in numbers improve readability

num = 1_000_000_000
print(num)

Underscores don’t affect the value.


8️⃣ range() is memory‑efficient

r = range(0, 10_000_000_000)

range doesn’t store all numbers—values are generated on demand.


9️⃣ Functions are first‑class objects

def greet(name):
    return f"Hello {name}"

say_hi = greet
say_hi("Python")

Functions can be stored, passed, and returned like variables.


🔟 try blocks can have else

try:
    risky()
except Exception:
    print("Error")
else:
    print("Success")

else runs only if no exception occurs.


1️⃣1️⃣ Dictionaries preserve insertion order (Python 3.7+)

d = {"a":1, "b":2, "c":3}
list(d)

Output:

['a', 'b', 'c']

1️⃣2️⃣ id() shows object identity

a = []
b = a
c = []

id(a) == id(b)  # True
id(a) == id(c)  # False

Same values ≠ same object.


1️⃣3️⃣ Small integers are cached

a = 100
b = 100
a is b   # True

x = 1000
y = 1000
x is y   # False (often)

Use == for value comparison, not is.


1️⃣4️⃣ The Ellipsis object exists

print(...)        # Ellipsis
print(type(...))  # <class 'ellipsis'>

Used in advanced slicing (e.g., NumPy).


1️⃣5️⃣ Shallow vs Deep Copy

import copy

x = [[1,2],[3,4]]
y = x.copy()
z = copy.deepcopy(x)
  • copy() → outer list copied, inner lists shared
  • deepcopy() → everything copied

End of Fun Facts

This file is part of a continuous Python learning journey.