π Stepping into Python: A Beginner's Guide π
Hey everyone! π Iβve taken my first step into the world of Python, and Iβm excited to share what Iβve learned so far. Python is known for being simple, powerful, and widely used in various fields like web development, data science, and automation. Letβs dive in! π
πΉ What is Python? π€
Python is a beginner-friendly programming language that supports multiple paradigms: β
Procedural
β
Object-Oriented
β
Functional Programming
It has a huge community, an extensive standard library, and tons of third-party packages.
πΉ Keywords in Python π
Keywords are special reserved words that cannot be used as variable or function names. Examples: if
, else
, for
, while
, def
, class
, import
, return
, True
, False
, None
.
πΉ Mutability & Immutability π
π Mutable (Can Change): Lists ([]
), Dictionaries ({}
), Sets ({}
)
π Immutable (Cannot Change): Tuples (()
), Strings (""
), Integers, Floats
πΉ Operators in Python βββοΈβ
Operators help us perform calculations and comparisons.
β
Arithmetic: +
, -
, *
, /
, %
β
Comparison: ==
, !=
, <
, >
β
Logical: and
, or
, not
β
Assignment: =
, +=
, -=
, *=
πΉ Type Casting π
Type casting means converting one data type into another.
Examples:
int("10") # Converts string to integer
float(5) # Converts integer to float
str(25) # Converts integer to string
πΉ Conditionals π€οΈ
Conditionals help us make decisions in a program.
age = 18
if age >= 18:
print("You are an adult")
elif age == 17:
print("Almost there!")
else:
print("You are a minor")
πΉ Loops π
Loops repeat a block of code multiple times.
πΉ For Loop (Iterates over a sequence)
for i in range(5):
print(i)
πΉ While Loop (Runs until a condition is false)
count = 0
while count < 5:
print(count)
count += 1
πΉ Functions π οΈ
Functions help organize code into reusable blocks.
def greet(name):
return f"Hello, {name}!"
print(greet("Alice"))
πΉ Iterators & Generators πβ‘
π Iterator: Used to iterate over collections like lists.
nums = [1, 2, 3]
iter_nums = iter(nums)
print(next(iter_nums)) # Output: 1
π Generator: Uses yield
for efficient memory usage.
def my_gen():
yield 1
yield 2
yield 3
for num in my_gen():
print(num)
πΉ Lambda, Map, Reduce, Filter ποΈ
β Lambda (Anonymous Function)
square = lambda x: x * x
print(square(5)) # Output: 25
β Map (Applies function to all items in iterable)
nums = [1, 2, 3]
print(list(map(lambda x: x * 2, nums))) # Output: [2, 4, 6]
β Reduce (Reduces iterable to a single value)
from functools import reduce
nums = [1, 2, 3]
sum = reduce(lambda x, y: x + y, nums)
print(sum) # Output: 6
β Filter (Filters elements based on condition)
nums = [1, 2, 3, 4, 5]
even_nums = list(filter(lambda x: x % 2 == 0, nums))
print(even_nums) # Output: [2, 4]
π₯ Want to Explore More?
Iβm documenting my journey on GitHub! Check out my repository: Python Repo π
Iβll keep updating my learning. Stay tuned! π Letβs grow together! π
#Python #Learning #Coding #Beginners #DataScience #AI