Python Learning
5.84K subscribers
546 photos
2 videos
85 files
120 links
Python learning resources

Beginner to advanced Python guides, cheatsheets, books and projects.

For data science, backend and automation.
Join πŸ‘‰ https://rebrand.ly/bigdatachannels

DMCA: @disclosure_bds
Contact: @mldatascientist
Download Telegram
Keywords in Python
❀4
🧠 Learn to Trace Code by Hand

Before running code, pause and predict the output. This builds real understanding.

Consider this:
x = 0

for i in range(3):
x += i

print(x)


Walk through slowly.

1. Start: x = 0

2. i = 0 β†’ x = 0

3. i = 1 β†’ x = 1

4. i = 2 β†’ x = 3

Final output:
3


This habit strengthens your debugging ability more than passive reading ever will.

Try this daily with small snippets.
❀5
Python Basics Cheat Sheet (Beginner Friendly)
❀4
Forwarded from Programming Quiz Channel
Which Python library is the most commonly used for numerical computing and matrix operations?
Anonymous Quiz
12%
Matplotlib
81%
NumPy
5%
Flask
2%
Seaborn
Forwarded from Programming Quiz Channel
Which Python feature allows to modify behavior of other functions?
Anonymous Quiz
50%
Decorators
26%
Iterators
20%
Generators
3%
Closures
🐍 Python Functions (def) βš™οΈ

Functions help organize code into reusable blocks, making programs cleaner and more efficient. Essential for writing modular and scalable code.

πŸ‘‰ They are very important for avoiding repetitive code and building complex applications.

πŸ”Ή 1. What is a Function?

A function is a block of code that only runs when it is called. You can pass data, known as parameters, into a function.

Example:
def greet():
print("Hello from a function!")

πŸ”Ή 2. Defining & Calling a Function

We use the def keyword to define a function, then call it by its name.

Syntax:
def function_name(parameters):
# code to execute
function_name(arguments) # call the function

Example:
def say_hello():
print("Hello, Python learner!")

say_hello() # calling the function

Output: Hello, Python learner!

πŸ”Ή 3. Functions with Parameters & Arguments

Parameters are variables listed inside the parentheses in the function definition. Arguments are the actual values sent when calling the function.

Example:
def welcome_user(name): # 'name' is a parameter
print(f"Welcome, {name}!")

welcome_user("Alice") # "Alice" is an argument
welcome_user("Bob")

Output:
Welcome, Alice!
Welcome, Bob!

πŸ”Ή 4. Return Values

Functions can return data as a result using the return keyword.

Example:
def add_numbers(a, b):
return a + b

result = add_numbers(5, 7)
print(result)

Output: 12

πŸ”Ή 5. Common Function Uses

β€’ Calculations: Performing mathematical operations.
β€’ Data Processing: Transforming inputs.
β€’ User Interaction: Handling prompts and responses.
β€’ Code Reusability: Doing the same task many times.

🎯 Today's Goal

βœ”οΈ Understand what functions are
βœ”οΈ Define and call functions
βœ”οΈ Use parameters and arguments
βœ”οΈ Return values from functions

πŸ‘‰ Functions are fundamental building blocks in almost every Python project.
❀7
Learn Python

This is Scrimba's official Python course featuring their unique interactive scrim format. It offers 58 interactive video lessons where you can pause the screencast and edit the instructor's code directly in your browser with no local setup required. Its great for hands-on learners who want to code actively during the lesson rather than passively watching. No prerequisites are required.

πŸ“š 58 interactive lessons covering Python fundamentals: variables, data types, strings, lists, dictionaries, loops, functions, and file handlingβ€”all with built-in coding challenges

⏰ Duration: 5.6 hours

πŸƒβ€β™‚οΈ Self Paced with immediate start

πŸ† Certificate: Free completion certificate included

Created by πŸ‘¨β€πŸ«: Olof Paulson & Scrimba Team

πŸ”— Course Link


#Python #InteractiveLearning #FreeCertificate

Join Python Learning for more
❀5
🐍Python Lists (Data Structures) πŸ“¦

πŸ”Ή 1. What is a List?

A list is a sequence of values (items). They are ordered, changeable (mutable), and allow duplicate members. Defined by square brackets [].

Example:
my_list = ["apple", 3.14, True, 100]
print(my_list)

Output: ['apple', 3.14, True, 100]

πŸ”Ή 2. Accessing List Items

Items are accessed by their index, which starts at 0 for the first item.

Example:
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # First item
print(fruits[2]) # Third item
print(fruits[-1]) # Last item

Output:
apple
cherry
cherry

πŸ”Ή 3. Modifying List Items

You can change an item by referring to its index.

Example:
colors = ["red", "green", "blue"]
colors[1] = "yellow" # Change 'green' to 'yellow'
print(colors)

Output: ['red', 'yellow', 'blue']

πŸ”Ή 4. Adding Items to a List

β€’ .append(): Adds an item to the end of the list.
β€’ .insert(index, item): Adds an item at a specific index.

Example:
names = ["Alice", "Bob"]
names.append("Charlie") # Add to end
names.insert(0, "David") # Add at the beginning
print(names)

Output: ['David', 'Alice', 'Bob', 'Charlie']

πŸ”Ή 5. Removing Items from a List

β€’ .remove(item): Removes the first occurrence of a specified item.
β€’ .pop(index): Removes (and returns) the item at a specified index (or the last item if no index is given).
β€’ del list[index]: Deletes the item at a specific index.

Example:
numbers = [10, 20, 30, 20, 40]
numbers.remove(20) # Removes first '20'
del numbers[0] # Removes '10'
print(numbers)

Output: [30, 20, 40]

🎯 Today's Goal(What you should do)

βœ”οΈ Understand what lists are and how to create them
βœ”οΈ Access items using indexing
βœ”οΈ Modify, add, and remove items from lists
❀8
🐍 Python For Loops (Iteration) πŸ”„

For loops are used to iterate over a sequence (like a list, tuple, string, or range) or other iterable objects. They let you execute a block of code repeatedly for each item.

πŸ‘‰ They are essential for automating tasks and processing collections of data efficiently.

πŸ”Ή 1. What is a For Loop?

A for loop executes a set of statements, once for each item in a collection.

Example:
for character in "Python":
print(character)

Output:
P
y
t
h
o
n

πŸ”Ή 2. Looping Through a List

This is one of the most common uses: going through each item in a list.

Syntax:
for item in list_name:
# code to execute for each item

Example:
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(f"I like {fruit}.")

Output:
I like apple.
I like banana.
I like cherry.

πŸ”Ή 3. The range() Function

The range() function generates a sequence of numbers, often used to loop a specific number of times.

β€’ range(stop): Numbers from 0 up to (but not including) stop.
β€’ range(start, stop): Numbers from start up to (not including) stop.
β€’ range(start, stop, step): Numbers from start up to stop, increasing by step.

Example:
for i in range(3): # Loop 3 times (0, 1, 2)
print(f"Iteration {i}")

Output:
Iteration 0
Iteration 1
Iteration 2

πŸ”Ή 4. break and continue Statements

β€’ break: Stops the loop completely, even if the iterable hasn't finished.
β€’ continue: Skips the rest of the current iteration and moves to the next.

Example (break):
for number in range(1, 6):
if number == 4:
break # Stop when number is 4
print(number)

Output:
1
2
3

Example (continue):
for item in ["A", "B", "C", "D"]:
if item == "C":
continue # Skip 'C'
print(item)

Output:
A
B
D

🎯 Today's Goal(What you should do)

βœ”οΈ Understand what for loops are
βœ”οΈ Iterate over lists, strings, and ranges (using your Python editor)
βœ”οΈ Use break and continue to control loop flow (using your Python editor)
❀6πŸ”₯2
🐍 Python If-Else Statements (Conditionals) πŸ€”

If-Else statements allow your program to make decisions and execute different code blocks based on conditions. They are fundamental for creating dynamic and responsive applications.

πŸ‘‰ Essential for controlling the flow of your program.

πŸ”Ή 1. What are Conditional Statements?

They test a condition. If the condition is True, one block of code runs. If False, another block (or nothing) might run.

Example:
temperature = 25
if temperature > 20:
print("It's warm!")

Output: It's warm!

πŸ”Ή 2. The if Statement

The simplest conditional, executing code only when a condition is True.

Syntax:
if condition:
# code to run if condition is True

Example:
age = 18
if age >= 18:
print("You are an adult.")

Output: You are an adult.

πŸ”Ή 3. The else Statement

Executes a block of code when the if condition is False.

Syntax:
if condition:
# code if True
else:
# code if False

Example:
score = 75
if score >= 90:
print("Excellent!")
else:
print("Good effort!")

Output: Good effort!

πŸ”Ή 4. The elif (Else If) Statement

Allows you to check multiple conditions sequentially. If the first if is False, it checks elif, and so on.

Syntax:
if condition1:
# code if condition1 is True
elif condition2:
# code if condition2 is True
else:
# code if all conditions are False

Example:
time = 14
if time < 12:
print("Good morning!")
elif time < 18:
print("Good afternoon!")
else:
print("Good evening!")

Output: Good afternoon!

πŸ”Ή 5. Short Hand If / Ternary Operator

A concise way to write simple if-else statements on a single line.

Example:

a = 10
b = 5
print("A is greater") if a > b else print("B is greater")

Output: A is greater

🎯 Today's Goal(What you should do)

βœ”οΈ Understand how to use if, elif, and else
βœ”οΈ Make your programs respond to different inputs
βœ”οΈ Use shorthand for simple conditions

πŸ‘‰ Conditional statements are the backbone of any interactive and logical Python program. It's crucial you understand them well.
❀4
Forwarded from Programming Quiz Channel
Which Python keyword allows defining anonymous functions?
Anonymous Quiz
24%
func
66%
lambda
7%
inline
3%
quick
❀4
Automating WhatsApp with Python
❀8
Forwarded from Programming Quiz Channel
What is the output in Python?
0.1 + 0.2 == 0.3
Anonymous Quiz
61%
True
30%
False
6%
Error
3%
Depends
🐍 Python Dictionaries (Key-Value Pairs) πŸ”‘

Dictionaries are unordered collections of data that store items in key-value pairs. They are incredibly powerful for organizing and quickly accessing related information.

πŸ‘‰ Ideal for representing real-world objects with unique identifiers (keys).

πŸ”Ή 1. What is a Dictionary?

A mutable, unordered collection where each item has a unique key and an associated value. Defined by curly braces {}.

Example:
person = {"name": "Alice", "age": 30, "city": "New York"}
print(person)

Output: {'name': 'Alice', 'age': 30, 'city': 'New York'}

πŸ”Ή 2. Accessing Dictionary Items

Access values using their associated key inside square brackets [] or with the .get() method.

Example:
student = {"id": 101, "name": "Bob", "grade": "A"}
print(student["name"])
print(student.get("grade"))

Output:
Bob
A

πŸ”Ή 3. Adding and Modifying Items

To add a new item, assign a value to a new key. To modify, assign a new value to an existing key.

Example:
car = {"brand": "Ford", "model": "Mustang"}
car["year"] = 2020 # Add new item
car["model"] = "Explorer" # Modify existing item
print(car)

Output: {'brand': 'Ford', 'model': 'Explorer', 'year': 2020}

πŸ”Ή 4. Removing Items

β€’ del dict[key]: Removes the item with the specified key.
β€’ .pop(key): Removes (and returns) the item with the specified key.
β€’ .clear(): Empties the entire dictionary.

Example:
settings = {"theme": "dark", "sound": "on", "notifications": "off"}
del settings["sound"] # Remove by key
print(settings)
settings.pop("theme") # Also removes by key
print(settings)

Output:
{'theme': 'dark', 'notifications': 'off'}
{'notifications': 'off'}

πŸ”Ή 5. Looping Through a Dictionary

You can loop through keys, values, or both (items).

Example:
for k, v in person.items(): # Loops through key-value pairs
print(f"{k}: {v}")

Output:
name: Alice
age: 30
city: New York

🎯 Today's Goal(What you should do)

βœ”οΈ Understand how dictionaries store data in key-value pairs
βœ”οΈ Add, access, modify, and remove dictionary items
βœ”οΈ Iterate over keys, values, or items
❀5