DEV Community

Cover image for 10 Python Tips I Wish I Knew as a Beginner ๐Ÿ
Chimezie Nwankwo
Chimezie Nwankwo

Posted on

10 Python Tips I Wish I Knew as a Beginner ๐Ÿ

When I first started learning Python, I wasted hours trying to figure out things that now feel so simple. If youโ€™re just starting your Python journey, these tips will save you time, confusion, and frustration.

Here are 10 Python tips I wish I knew as a beginner ๐Ÿ‘‡

1. Use 'print()' Wisely

Debugging? Donโ€™t just print variables randomly.

Use f-strings to format your output:


python
name = "Alice"
age = 20
print(f"My name is {name}, and I am {age} years old.")
---
2. Learn List Comprehensions Early

Instead of writing long loops:
squares = []
for i in range(5):
    squares.append(i * i)
DO THIS :
squares = [i * i for i in range(5)]

Cleaner, shorter, more Pythonic.
---
3. The Power of enumerate()

Instead of:
i = 0
for item in ["a", "b", "c"]:
    print(i, item)
    i += 1
USE:
for i, item in enumerate(["a", "b", "c"]):
    print(i, item)
---
4. Use zip() for Parallel Iteration
names = ["Alice", "Bob", "Charlie"]
scores = [90, 85, 92]

for name, score in zip(names, scores):
    print(f"{name}: {score}")
---
5. Master Slicing

Python lets you grab parts of a list easily:
nums = [0, 1, 2, 3, 4, 5]
print(nums[1:4])   # [1, 2, 3]
print(nums[:3])    # [0, 1, 2]
print(nums[-2:])   # [4, 5]

To be continued....
Enter fullscreen mode Exit fullscreen mode

Top comments (0)