Skip to main content

Command Palette

Search for a command to run...

šŸš€ Learning Python Basics in Public: Tuples, Lists, Dicts, Functions, and More

Published
•2 min read•View as Markdown
N

Hi, I'm Nishant—a beginner coder and tech enthusiast. I enjoy learning and working with Python, Linux, and Git. I'm also starting to explore DevOps to learn how to build, deploy, and maintain software efficiently. I use trusted resources like Harvard’s CS50P and ChatGPT to guide my learning journey. On my Hashnode page, I share simple tips and insights about coding and DevOps practices as I grow my skills each day. Join me on my journey to learn and share knowledge!

By Nishant Kumar – Follow my journey @LumenX21

šŸ“Œ Why I’m Writing This

I recently started learning core Python concepts like data structures, functions, and comprehensions—and I decided to learn in public. This is a recap of what I’ve learned so far, explained in my own words with code examples. If you're just getting started or revisiting the basics, this is for you!


1. 🧱 Basic Data Structures

🧊 Tuples

  • Immutable, ordered collection

  • Use them when you want to ensure the data doesn’t change

pythonCopyEditpoint = (10, 20)
x, y = point  # unpacking
print(x, y)

šŸ“‹ Lists

  • Mutable and ordered

  • Great for dynamic data

pythonCopyEditfruits = ['apple', 'banana']
fruits.append('mango')
fruits.remove('banana')
fruits.insert(1, 'orange')
fruits.sort()
print(fruits)

šŸ—‚ļø Dictionaries

  • Key-value pairs

  • Super useful for mappings

pythonCopyEditperson = {'name': 'Alice', 'age': 25}
person['age'] = 26  # update
person['city'] = 'Delhi'  # add new
print(person)

šŸ”¢ Sets

  • Unordered, no duplicates

  • Good for membership tests and math ops

pythonCopyEdita = {1, 2, 3}
b = {2, 3, 4}
print(a | b)  # union
print(a & b)  # intersection

2. āš™ļø Functions and Parameters

šŸ“Œ Function Basics

pythonCopyEditdef greet(name):
    return f"Hello, {name}!"

✨ Default Arguments

pythonCopyEditdef greet(name="world"):
    return f"Hello, {name}!"

⚔ Lambda Functions

pythonCopyEditsquared = lambda x: x * x
print(squared(4))

šŸ“¦ args and *kwargs

pythonCopyEditdef show(*args, **kwargs):
    print(args)
    print(kwargs)

🧼 Decorators

pythonCopyEditdef decorator(func):
    def wrapper():
        print("Before function")
        func()
        print("After function")
    return wrapper

@decorator
def hello():
    print("Hello!")

hello()

3. šŸ” Comprehensions

āœ… List

pythonCopyEditsquares = [x * x for x in range(5)]

āœ… Dictionary

pythonCopyEditeven_map = {x: x % 2 == 0 for x in range(5)}

āœ… Set

pythonCopyEditunique = {x for x in [1, 2, 2, 3]}

āœ… Nested

pythonCopyEditgrid = [[i * j for j in range(3)] for i in range(3)]

4. 🧰 Built-in Functions I Found Super Useful

pythonCopyEditnames = ['Alice', 'Bob', 'Charlie']

for i, name in enumerate(names):
    print(i, name)

numbers = [10, 20, 30]
print(sum(numbers), min(numbers), max(numbers))

a = [1, 2]
b = ['a', 'b']
print(list(zip(a, b)))

šŸ’¬ Final Thoughts

Learning in public is scary but powerful. Writing this helped reinforce what I learned—and I hope it helps you too.

If you’ve got tips or corrections, please drop them in the comments!


šŸ™Œ Connect With Me

Let’s keep learning and building—in public! šŸš€

More from this blog