Learn Coding
57 subscribers
21 links
Download Telegram
πŸ“Œ What is a Variable?

Think of your phone contacts list
You save a number under a name so you do not have to remember the actual digits
A variable is the exact same idea

Instead of writing 2500 every time in your code
You save it under a name and use that name instead

salary = 2500
print(salary) # 2500


You can also update it anytime:

salary = 2500
salary = 3000
print(salary) # 3000


That is why it is called a variable β€” it can vary
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ“Œ Rules for Naming Variables

You can name a variable almost anything but there are rules:

βœ”οΈ Can start with a letter or underscore
βœ”οΈ Can have letters, numbers, and underscores
βœ”οΈ Use lowercase with underscores β€” this is the Python way

❌ Cannot start with a number
❌ Cannot have spaces
❌ Cannot use special characters like @, !, $

Good:
user_name = "Allah"
total_price = 150
is_logged_in = True


Bad:
1name = "Allah"      # starts with number
total price = 150 # has a space
total@price = 150 # special character


Also β€” always make your names meaningful
x = 150 works but total_price = 150 is 10x easier to read later
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ“Œ The 4 Main Data Types

Not everything you store is the same kind of thing
A name is different from a number, a yes/no is different from both
Python has types for each:

1. int β€” whole numbers
age = 22
followers = 10000


2. float β€” decimal numbers
price = 9.99
temperature = 36.6


3. str β€” text
name = "Allah"
message = "Welcome to the channel"

Always wrap text in quotes β€” single or double both work

4. bool β€” True or False only
is_online = True
is_banned = False

True and False must start with capital letters
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ“Œ Checking What Type Something Is

Python has a built in function called type()
Use it whenever you are not sure what type a variable is

name = "Allah"
age = 69
price = 0.01
is_online = True

print(type(name)) # <class 'str'>
print(type(age)) # <class 'int'>
print(type(price)) # <class 'float'>
print(type(is_online)) # <class 'bool'>


Run this and see what prints
This will save you a lot of confusion when debugging later
Please open Telegram to view this post
VIEW IN TELEGRAM
⚠️ Most Common Beginner Mistake

Mixing types without converting them first

age = 22
print("I am " + age + " years old") # CRASH


This crashes because you cannot combine text and a number directly

Fix it by converting the number to text first:
age = 22
print("I am " + str(age) + " years old") # Works


Or use an f-string β€” we cover this properly next lecture:
age = 22
print(f"I am {age} years old") # Cleaner
Please open Telegram to view this post
VIEW IN TELEGRAM
🚨 Video Reference

Watch this after reading through all the posts

Python Full Course 2024 β€” freeCodeCamp

πŸ”– Watch from 16:45 to 47:44
Covers variables, all data types, and type conversion
Please open Telegram to view this post
VIEW IN TELEGRAM
✏️ Lecture 2 Homework

Create a Python file and store this info about yourself:

name = ""        # your name
age = 0 # your age
height = 0.0 # your height
is_student = True

print(f"Name: {name}")
print(f"Age: {age}")
print(f"Height: {height}")
print(f"Student: {is_student}")
print(f"Types: {type(name)}, {type(age)}, {type(height)}, {type(is_student)}")


Fill in your actual info, run it and screenshot the output
Bonus β€” add 3 more variables of your choice

⚠️ Next lecture drops in 2 days β€” Strings & User Input
Please open Telegram to view this post
VIEW IN TELEGRAM
This media is not supported in your browser
VIEW IN TELEGRAM
Should I start posting lectures quicker❓
Like 1 lecture per day‼️
Anonymous Poll
89%
Yesβœ”οΈ
11%
No❌
This media is not supported in your browser
VIEW IN TELEGRAM
πŸ“š π—Ÿπ—²π—°π˜π˜‚π—Ώπ—² 𝟯 β€” π—¦π˜π—Ώπ—Άπ—»π—΄π˜€ & π—¨π˜€π—²π—Ώ π—œπ—»π—½π˜‚π˜

Last lecture you learned how to store data in variables
This lecture we go deeper into the most used data type β€” strings
And we add something that makes your code actually feel alive β€” user input

This lecture covers:
➑️ Working with strings
➑️ f-strings β€” the clean way to mix variables with text
➑️ String methods β€” free tools Python gives you
➑️ Taking input from the user
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ“Œ Strings in Depth

A string is just text β€” anything wrapped in quotes

name = "Allah"
message = 'Welcome to the channel'
number_as_text = "1234" # this is text, not a number


You can combine strings together β€” this is called concatenation:

first = "Allah"
second = " Hu Akbar"
print(first + second) # Allah Hu Akbar


And repeat them:

print("Ha" * 3)  # HaHaHa
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ“Œ F-strings

We teased this last lecture β€” now we cover it properly

The messy way:
name = "Allah"
age = 22
print("My name is " + name + " and I am " + str(age) + " years old")


The clean way with f-strings:
name = "Allah"
age = 22
print(f"My name is {name} and I am {age} years old")


Just put f before the opening quote and wrap variables in curly braces
You can even do math inside:

price = 100
discount = 20
print(f"Final price: {price - discount}") # Final price: 80


From now on always use f-strings β€” forget the + method
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ“Œ String Methods

Python gives you built in tools to work with strings
You use them with a dot after the variable

name = "  allah  "
print(name.upper()) # ALLAH
print(name.lower()) # allah
print(name.strip()) # allah β€” removes extra spaces
print(name.strip().title()) # Allah β€” capitalizes first letter


message = "Welcome to the channel"
print(message.replace("channel", "group")) # Welcome to the group
print(message.split(" ")) # ['Welcome', 'to', 'the', 'channel']
print(len(message)) # 22


email = "allahlovesram69@gmail.com"
print(email.startswith("allah")) # True
print(email.endswith(".com")) # True
print("gmail" in email) # True


You will use these constantly when building bots
Bots deal with text all day β€” these are your best friends
πŸ“Œ Taking Input from the User

input() lets the user type something and your code responds

name = input("What is your name? ")
print(f"Hello {name}!")


Run this and type your name β€” your code just talked back to you

Important β€” input() always gives you a string
Even if the user types a number you get it as text
So if you need to do math with it, convert it first:

age = int(input("How old are you? "))
print(f"In 10 years you will be {age + 10}")
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ“Œ Putting It All Together

name = input("Enter your name: ").strip().title()
age = int(input("Enter your age: "))
city = input("Enter your city: ").strip()

print(f"Name : {name}")
print(f"Age : {age}")
print(f"City : {city}")
print(f"In 5 years you will be {age + 5}")
print(f"Your name has {len(name)} letters")


Notice line 1 β€” we take input, strip spaces, and capitalize all in one line
This is how real clean code looks
Please open Telegram to view this post
VIEW IN TELEGRAM
🚨 Video Reference

Watch this after reading through all the posts

Python Full Course 2024 β€” freeCodeCamp

πŸ”– Watch from 47:44 β†’ 1:24:01
Covers strings, strip, title case, interactive mode, arithmetic, and formatting numbers
Please open Telegram to view this post
VIEW IN TELEGRAM
✏️ Lecture 3 Homework

Build a personal info card generator
Ask the user for name, age, city and hobby then print a formatted card:

name = input("Name: ").strip().title()
age = int(input("Age: "))
city = input("City: ").strip().title()
hobby = input("Hobby: ").strip().lower()

print("====================")
print(f" Name : {name}")
print(f" Age : {age}")
print(f" City : {city}")
print(f" Hobby : {hobby}")
print(f" Name length: {len(name)} letters")
print("====================")


Screenshot your output
Bonus β€” add one more input of your choice

⚠️ Next lecture drops tomorrow β€” Conditionals
Please open Telegram to view this post
VIEW IN TELEGRAM
This media is not supported in your browser
VIEW IN TELEGRAM
⚠️ Made a discussion (Comments Section) for this Group!!
πŸ’‘You can ask any questions there
Please open Telegram to view this post
VIEW IN TELEGRAM