š Learning Python Basics in Public: Tuples, Lists, Dicts, Functions, and More
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! š


