Python basic to advance
43 subscribers
131 photos
98 links
Learn Python daily with bite-sized lessons, code examples, output previews, and fun quizzes. Perfect for beginners and enthusiasts!
Download Telegram
Which Python function is used to display output (text or data) to the console?
Anonymous Quiz
0%
show()
33%
print()
67%
display()
0%
output()
Here's your Telegram post for Day 2 of the Python learning series, including the quiz question in JSON format:

---

🐍 **Python Learning Series - Day 2: Variables and Data Types** 🚀

Welcome back, Pythonistas! Today, we're unlocking the secret to storing and managing information in your programs: **Variables and Data Types**! 🧠

Think of variables as named containers that hold different kinds of data. Whether it's numbers, text, or even true/false values, variables are essential for making your code dynamic and interactive. Understanding what type of data your variable holds helps Python know how to work with it. Let's dive in and see them in action! ✨

```python
# Day 2: Variables and Data Types
# Variables are like labeled containers for your data!

# 1. Integer (whole numbers without decimals)
my_age = 30
print(f"My age: {my_age}, Type: {type(my_age)}")

# 2. Float (numbers with decimals)
my_height = 1.75
print(f"My height: {my_height}, Type: {type(my_height)}")

# 3. String (text, enclosed in single or double quotes)
my_name = "Alice"
print(f"My name: {my_name}, Type: {type(my_name)}")

# 4. Boolean (True or False values, case-sensitive)
is_learning_python = True
print(f"Am I learning Python? {is_learning_python}, Type: {type(is_learning_python)}")

# You can easily change a variable's value!
my_age = my_age + 1 # Incrementing the age by 1
print(f"Next year, my age will be: {my_age}")

message = "Python is super cool! 😎 Keep practicing!"
print(message)
```

Output example:
```
My age: 30, Type: <class 'int'>
My height: 1.75, Type: <class 'float'>
My name: Alice, Type: <class 'str'>
Am I learning Python? True, Type: <class 'bool'>
Next year, my age will be: 31
Python is super cool! 😎 Keep practicing!
```

💡 **Your Challenge:**
1. Create a variable named `favorite_city` and assign your favorite city (as a string) to it.
2. Create another variable `current_temp` and store the current temperature (as a float, e.g., 25.5) in it.
3. Print both variables along with their data types, just like we did in the examples!

Share your solutions or questions in the comments below! 👇 Let's keep building our Python skills! ✅

---
Day 2: Variables and Data Types \- Code & Output
What is the correct way to assign the integer value `100` to a variable named `score` in Python?
Anonymous Quiz
0%
score = 100
0%
score == 100
0%
100 = score
0%
int score = 100
🚀 Day 3 of our Python journey is here! Today, we're diving into the core of computation: **Operators**! 💡

Operators are special symbols that perform operations on variables and values. From basic math to complex logic, they are your essential tools to manipulate data and make your programs do amazing things. Understanding them is key to writing effective Python code. Let's explore some common types! 👇

```python
# Day 3: Operators in Python

# Arithmetic Operators (+, -, *, /, //, %, **)
a = 15
b = 4
print(f"Addition (a + b): {a + b}")
print(f"Subtraction (a - b): {a - b}")
print(f"Multiplication (a * b): {a * b}")
print(f"Division (a / b): {a / b}") # Returns a float
print(f"Floor Division (a // b): {a // b}") # Returns an integer (discards fraction)
print(f"Modulus (a % b): {a % b}") # Returns the remainder
print(f"Exponentiation (a ** 2): {a ** 2}") # a to the power of 2

print("-" * 20)

# Comparison Operators (==, !=, <, >, <=, >=)
x = 10
y = 7
print(f"Equal to (x == y): {x == y}")
print(f"Not equal to (x != y): {x != y}")
print(f"Greater than (x > y): {x > y}")
print(f"Less than (x < y): {x < y}")
print(f"Greater or equal (x >= 10): {x >= 10}")

print("-" * 20)

# Logical Operators (and, or, not)
is_sunny = True
is_warm = False
print(f"AND (is_sunny and is_warm): {is_sunny and is_warm}") # Both must be True
print(f"OR (is_sunny or is_warm): {is_sunny or is_warm}") # At least one must be True
print(f"NOT (not is_warm): {not is_warm}") # Reverses the boolean value

print("-" * 20)

# Assignment Operator (= and shorthand like +=, -=)
score = 100
score += 50 # Equivalent to: score = score + 50
print(f"Score after += 50: {score}")

total_items = 10
total_items -= 2 # Equivalent to: total_items = total_items - 2
print(f"Total items after -= 2: {total_items}")
```

Output example:
```
Addition (a + b): 19
Subtraction (a - b): 11
Multiplication (a * b): 60
Division (a / b): 3.75
Floor Division (a // b): 3
Modulus (a % b): 3
Exponentiation (a ** 2): 225
--------------------
Equal to (x == y): False
Not equal to (x != y): True
Greater than (x > y): True
Less than (x < y): False
Greater or equal (x >= 10): True
--------------------
AND (is_sunny and is_warm): False
OR (is_sunny or is_warm): True
NOT (not is_warm): True
--------------------
Score after += 50: 150
Total items after -= 2: 8
```

🤔 **Your Challenge!**
What would be the output of these two expressions?
1. `(20 - 5 * 2) // 3`
2. `True and not (5 > 10)`

Try to predict before running it in a Python interpreter! Share your answers below! 👇

***
Day 3: Operators in Python \- Code & Output
Which of the following operators in Python is used to check if two values are *not* equal?
Anonymous Quiz
0%
==
0%
=
0%
!=
0%
>=
🚀 Welcome back to Python Day 4! Today, we're diving into the heart of decision-making in code: **Conditional Statements**! 🚦 Ever wondered how programs choose different paths based on conditions? 🤔 That's where `if`, `elif` (short for "else if"), and `else` come in!

They allow your code to execute specific blocks only when certain criteria are met. This is fundamental for creating dynamic and responsive programs. Get ready to make your Python scripts smarter and more interactive! Let's explore how to control the flow! 👇

```python
# Day 4: Conditional Statements (if, elif, else)

# Let's check a student's grade based on their score
score = 85

if score >= 90:
print("Excellent! You got an A. 🎉")
elif score >= 80:
print("Great job! You got a B. 👍")
elif score >= 70:
print("Good effort! You got a C. 😊")
elif score >= 60:
print("You passed! You got a D. 😉")
else:
print("Keep practicing! You need to improve. 💪")

print("n--- Grade check complete ---")
```

Output example:
```
Great job! You got a B. 👍

--- Grade check complete ---
```

**Small Challenge:**
What would the output be if `score` was `95`? How about `55`? Try changing the `score` variable in the code and observe the different outcomes! Can you add another `elif` condition for a specific score, like `score == 100`? 🤔

---
Day 4: Conditional Statements \(if, elif, else\) \- Code & Output
Consider the following Python code:

```python x = 15 if x > 10: print('First Block') elif x > 5: print('Second Block') else: print('Third Block') ``` What will be the output when this code is executed?
Anonymous Quiz
0%
First Block
0%
Second Block
0%
Third Block
0%
Error
🚀 Python Day 5 is here, and it's all about making your code work smarter, not harder! Today, we're unlocking the power of *loops*. Loops (`for` and `while`) are fundamental for automating repetitive tasks and iterating through data. Get ready to write efficient and concise code! Let's loop into it! ✨

---

```python
# --- For Loop Example (iterating over a list) ---
print("--- For Loop Example ---")
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(f"I love {fruit}!")

print("n--- Another For Loop (with range) ---")
# range(start, stop, step) generates a sequence of numbers
# range(3) generates 0, 1, 2
for i in range(3):
print(f"Iteration {i + 1}")

# --- While Loop Example (repeating based on a condition) ---
print("n--- While Loop Example ---")
num = 0
while num < 4: # Loop as long as num is less than 4
print(f"Current number: {num}")
num += 1 # Increment num; crucial to avoid an infinite loop!
```

---

Output example:
```
--- For Loop Example ---
I love apple!
I love banana!
I love cherry!

--- Another For Loop (with range) ---
Iteration 1
Iteration 2
Iteration 3

--- While Loop Example ---
Current number: 0
Current number: 1
Current number: 2
Current number: 3
```

---

### Your Turn! 💡
Create a Python script that:
1. Prints numbers from 1 to 5 using a `for` loop.
2. Calculates and prints the sum of numbers from 1 to 10 using a `while` loop.
Share your solutions! 👇

---
Day 5: Loops \(for and while\) \- Code & Output
🚀 **Python Learning Series - Day 6: Functions in Python!** 🚀

Hello Python learners! Today we're diving into one of the most fundamental concepts in programming: **Functions**! 💡 Functions help us write reusable, organized, and readable code. Instead of repeating the same logic, we can encapsulate it in a function and call it whenever needed. Get ready to streamline your code and make it much more powerful! Let's explore how to define and use them. ✍️

```python
# 1. Defining a simple function
def greet_user(name):
"""This function greets the user with their name."""
print(f"Hello, {name}! Welcome to Day 6 of our Python series.")

# 2. Defining a function that returns a value
def calculate_sum(num1, num2):
"""This function takes two numbers and returns their sum."""
return num1 + num2

# 3. Defining a function with a default parameter
def display_message(message="Keep learning Python!"):
"""This function displays a message, with a default if none is provided."""
print(message)

# Calling our functions
greet_user("Coding Enthusiast")

sum_result = calculate_sum(10, 25)
print(f"The sum of 10 and 25 is: {sum_result}")

display_message()
display_message("Functions make code modular!")
```

Output example:
```
Hello, Coding Enthusiast! Welcome to Day 6 of our Python series.
The sum of 10 and 25 is: 35
Keep learning Python!
Functions make code modular!
```

---

🔥 **Small Challenge:**
Create a Python function called `is_even` that takes one integer as an argument. The function should return `True` if the number is even, and `False` if it's odd. Test it with a few numbers! Share your solution in the comments! 👇

---
Day 6: Functions in Python \- Code & Output
What keyword is used to define a function in Python?
Anonymous Quiz
0%
func
0%
define
0%
def
0%
function
Hey Python learners! 🚀 Welcome to Day 7! Today, we're diving into two super important data structures: **Lists** and **Tuples**! 📚 Both allow you to store collections of items, but they have key differences in how you can modify them. Get ready to organize your data like a pro! 📋 Let's explore!

```python
# Day 7: Lists and Tuples - Organizing Your Data!

# --- Lists: Ordered, Mutable Collections (use square brackets []) ---
my_shopping_list = ["Milk", "Bread", "Eggs"]
print(f"Original List: {my_shopping_list}")

# Lists can be changed:
my_shopping_list.append("Butter") # Add an item
print(f"After adding Butter: {my_shopping_list}")

my_shopping_list[1] = "Cereal" # Change an item
print(f"After changing Bread to Cereal: {my_shopping_list}")

# Accessing elements by index
print(f"First item: {my_shopping_list[0]}")
print(f"Last item: {my_shopping_list[-1]}")

# --- Tuples: Ordered, Immutable Collections (use parentheses ()) ---
# Tuples are often used for fixed collections, like coordinates or RGB colors.
my_coordinates = (10.5, 20.3)
my_rgb_color = (255, 0, 0) # Red color

print(f"nOriginal Tuple (Coordinates): {my_coordinates}")
print(f"Original Tuple (RGB Color): {my_rgb_color}")

# Tuples cannot be changed after creation.
# If you uncomment the line below, it will cause a TypeError!
# my_coordinates[0] = 12.0 # This would raise an error!

# You can still access elements by index:
print(f"X-coordinate: {my_coordinates[0]}")

# Both Lists and Tuples support slicing!
print(f"Sliced List (first two items): {my_shopping_list[0:2]}")
print(f"Sliced Tuple (first two items): {my_rgb_color[0:2]}")
```

Output example:
```
Original List: ['Milk', 'Bread', 'Eggs']
After adding Butter: ['Milk', 'Bread', 'Eggs', 'Butter']
After changing Bread to Cereal: ['Milk', 'Cereal', 'Eggs', 'Butter']
First item: Milk
Last item: Butter

Original Tuple (Coordinates): (10.5, 20.3)
Original Tuple (RGB Color): (255, 0, 0)
X-coordinate: 10.5
Sliced List (first two items): ['Milk', 'Cereal']
Sliced Tuple (first two items): (255, 0)
```

**Challenge!** 🧠
Can you create a Python list of your 3 favorite fruits, then change the second fruit to something else, and finally convert that list into a tuple? Share your code snippet!

---
Day 7: Lists and Tuples \- Code & Output
Which of the following Python data structures is *mutable* (meaning its elements can be changed after creation)?
Anonymous Quiz
0%
List
0%
Tuple
0%
String
0%
Boolean
Here's your Telegram post and quiz question!

---

🎉 **Day 8: Dictionaries and Sets!** 🎉

Hello, Python learners! 👋 Today, we're diving into two incredibly versatile data structures: Dictionaries and Sets! 📚

* **Dictionaries** store data in `key: value` pairs, perfect for retrieving specific information quickly, much like looking up a word in a physical dictionary. 🔑
* **Sets** are unordered collections of *unique* items. They're super useful for keeping track of distinct elements and performing mathematical set operations like union or intersection. 💡

Let's explore how to use them! 👇

```python
# --- Dictionaries ---
print("--- Dictionaries ---")
# Creating a dictionary for a student's profile
student_profile = {
"name": "Alex",
"age": 22,
"major": "Computer Science",
"courses": ["Python Basics", "Web Development"]
}

print(f"Student Name: {student_profile['name']}")
print(f"Student Age (using .get()): {student_profile.get('age', 'N/A')}") # Safe access

# Modifying an existing value
student_profile["age"] = 23
# Adding a new key-value pair
student_profile["gpa"] = 3.9

print("nUpdated Student Profile:")
for key, value in student_profile.items():
print(f"- {key}: {value}")

# --- Sets ---
print("n--- Sets ---")
# Creating a set from a list with duplicates
numbers_list = [10, 20, 20, 30, 40, 40, 10, 50]
unique_numbers = set(numbers_list)
print(f"Original list: {numbers_list}")
print(f"Unique numbers (set): {unique_numbers}") # Order is not guaranteed

# Adding an element to a set
unique_numbers.add(60)
unique_numbers.add(20) # Adding an existing element has no effect
print(f"Set after adding 60: {unique_numbers}")

# Set operations
set_a = {1, 2, 3, 4, 5}
set_b = {4, 5, 6, 7, 8}

print(f"nSet A: {set_a}")
print(f"Set B: {set_b}")
print(f"Union (A | B): {set_a.union(set_b)}") # All unique elements from both
print(f"Intersection (A & B): {set_a.intersection(set_b)}") # Common elements
print(f"Difference (A - B): {set_a.difference(set_b)}") # Elements in A but not in B
```

Output example:
```
--- Dictionaries ---
Student Name: Alex
Student Age (using .get()): 23

Updated Student Profile:
- name: Alex
- age: 23
- major: Computer Science
- courses: ['Python Basics', 'Web Development']
- gpa: 3.9

--- Sets ---
Original list: [10, 20, 20, 30, 40, 40, 10, 50]
Unique numbers (set): {50, 20, 40, 10, 30}
Set after adding 60: {50, 20, 40, 10, 60, 30}

Set A: {1, 2, 3, 4, 5}
Set B: {4, 5, 6, 7, 8}
Union (A | B): {1, 2, 3, 4, 5, 6, 7, 8}
Intersection (A & B): {4, 5}
Difference (A - B): {1, 2, 3}
```

**Small challenge:** 🧠
Your turn! Create a dictionary called `book_details` for your favorite book, including its `title`, `author`, and `year`. Then, create a set called `unique_genres` with a few genres and add a new genre to it! Share your code snippets in the comments! 👇

---
Day 8: Dictionaries and Sets \- Code & Output