TGViewer
Artificial Intelligence Artificial Intelligence @machinelearning_deeplearning · 56.3K subscribers
Post #1853 4.95K
In the previous post, we successfully installed Python and VS Code and wrote our first Python program. Now, let's learn one of the most important concepts in programming.

📖 Phase 1: Programming Fundamentals

📌 Topic 4: Variables

A variable is a named container used to store data in memory. Instead of using the actual value repeatedly, we store it in a variable and use the variable name whenever needed.

Think of a variable like a labeled box. You can store different items inside the box, and whenever you need that item, you simply refer to the label instead of searching for the item.

Why Do We Need Variables?

Variables help us:

• Store data for later use.

• Reuse values multiple times.

• Make programs easier to read.

• Update values whenever required.

• Avoid writing the same value repeatedly.

Creating Variables in Python

In Python, you don't need to declare the data type. Simply assign a value using the "=" operator.

Example:

name = "Ajay"  
age = 29
salary = 400000


Here:

• "name" stores a string.

• "age" stores an integer.

• "salary" stores a number.

Printing Variables

You can display variable values using the "print()" function.

name = "Aman"  
age = 25

print(name)
print(age)


Output:

Aman  
25


Updating Variables

Variables can be changed anytime.

score = 80  
score = 95
print(score)


Output:

95


The old value is replaced with the new value.

Multiple Variable Assignment

You can assign multiple variables in one line.

x, y, z = 10, 20, 30  
print(x)
print(y)
print(z)


Output:

10  
20
30


Naming Rules for Variables

✅ Variable names can contain letters, numbers, and underscores.

✅ Variable names must start with a letter or underscore.

✅ Variable names are case-sensitive ("age" and "Age" are different).

❌ Variable names cannot start with a number.

❌ Variable names cannot contain spaces or special characters.

Good vs Bad Variable Names

✅ Good:

student_name = "Rahul"

total_marks = 450

is_logged_in = True

❌ Bad:

1name = "Rahul"

student name = "Rahul"

total-marks = 450

These will produce errors because they don't follow Python's naming rules.

Best Practices

• Use meaningful variable names.

• Follow the "snake_case" naming convention.

• Keep names short but descriptive.

• Avoid using Python keywords like "if", "for", "class", or "print" as variable names.

Key Takeaways

• A variable is used to store data.

• Variables make programs more readable and reusable.

• Python automatically determines the data type of a variable.

• Variable values can be updated anytime.

• Always use meaningful and valid variable names.

➡️ Double Tap ❤️ For More
  • ❤ 24
More from @machinelearning_deeplearning
  1. Sep 22, 2026🚀 Welcome back to our AI Engineer Roadmap! ❤️ In the previous posts, we learned about fun…
  2. Sep 21, 2026🚀 Welcome back to our AI Engineer Roadmap! ❤️ In the previous post, we explored functions…
  3. Sep 20, 2026In the previous post, we learned how conditional statements allow Python programs to make…
  4. Sep 19, 2026In the previous post, we explored Python operators and even tested ourselves with some tri…
  5. Sep 18, 2026In the previous post, we learned how to convert one data type into another using Type Cast…
  6. Sep 17, 2026In the previous post, we learned how to take input from users and display output. One impo…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →