🟢 Beginner  ·  Lesson 05

Variables and Data Types in Python

Python में Variables और Data Types

What is Variables and Data Types?

Variables and Data Types means variables store values in memory. Python automatically detects common data types like int, float, string, boolean, list and dictionary.

In real programs, this topic helps in storing names, marks and totals. Learn the idea first, then type the program yourself and compare the output.

💡 At a Glance
PointDetails
Course AreaCore Python
Basic programming concepts used to write Python programs.
Main Usestoring names, marks and totals
Example Filevariables-data-types.py
Practice FocusRun, change values, and explain the output line by line.

Why should you learn this?

  • It is useful for storing names, marks and totals.
  • It connects with checking data type before calculation.
  • It improves your ability to read, write and debug Python programs.

Important Terms

These terms are used directly in this lesson. Understand them before memorising the code.

TermMeaning
variableA name that stores a value in memory for later use.
intWhole number data type, such as 10 or -5.
floatDecimal number data type, such as 91.5.
stringText data written inside quotes, such as "Hello".
type()Built-in function used to check the data type of a value.

Syntax / Basic Pattern

The simple pattern is: prepare data, apply the concept, then show the result.

Basic Pattern
student_name = "Aarav"
age = 16
percentage = 91.5
is_pass = True
print(student_name, age, percentage, is_pass)
print(type(student_name))
print(type(age))
print(type(percentage))

Complete Example Program

Python – variables-data-types.py
student_name = "Aarav"
age = 16
percentage = 91.5
is_pass = True

print(student_name, age, percentage, is_pass)
print(type(student_name))
print(type(age))
print(type(percentage))
print(type(is_pass))

Expected Output

Aarav 16 91.5 True <class 'str'> <class 'int'> <class 'float'> <class 'bool'>

Program Explanation

  • student_name = "Aarav" stores a value in student_name.
  • age = 16 stores a value in age.
  • percentage = 91.5 stores a value in percentage.
  • is_pass = True stores a value in is_pass.
  • print(student_name, age, percentage, is_pass) displays information or calculated result on the screen.
  • print(type(student_name)) displays information or calculated result on the screen.
  • print(type(age)) displays information or calculated result on the screen.

Where will you use it?

  • Storing names, marks and totals.
  • Checking data type before calculation.
  • Creating forms and reports.

Common Mistakes

  • Writing code with wrong indentation.
  • Using input() value directly in calculations without converting it to int or float.
  • Using unclear variable names that make the program difficult to understand.

Practice Tasks

  1. Type the program in variables-data-types.py and run it.
  2. Change input values or sample data and observe the new output.
  3. Create one example related to storing names, marks and totals.
  4. Write 5 lines explaining the logic in your own words.

Summary

Variables and Data Types is not a theory-only topic. You should be able to explain the meaning, write the example, run it successfully, and use it in a small practical program.

Variables और Data Types क्या है?

Variables और Data Types ka matlab hai: Variables store values in memory. Python automatically detects common data types like int, float, string, boolean, list and dictionary. Simple words me, ye topic practical Python programs likhne me direct use hota hai.

Is topic ko sirf definition ke liye nahi, balki storing names, marks and totals jaise real examples ke liye practice karein.

यह क्यों सीखना जरूरी है?

  • Ye storing names, marks and totals me kaam aata hai.
  • Ye checking data type before calculation se bhi connected hai.
  • Isse aap code ka output aur errors better samajh paate hain.

Important Terms

TermMeaning
variableA name that stores a value in memory for later use.
intWhole number data type, such as 10 or -5.
floatDecimal number data type, such as 91.5.
stringText data written inside quotes, such as "Hello".
type()Built-in function used to check the data type of a value.

Syntax / Basic Pattern

Basic idea: pehle data तैयार करें, phir Python logic apply करें, aur finally result display करें.

Basic Pattern
student_name = "Aarav"
age = 16
percentage = 91.5
is_pass = True
print(student_name, age, percentage, is_pass)
print(type(student_name))
print(type(age))
print(type(percentage))

Complete Example Program

Python – variables-data-types.py
student_name = "Aarav"
age = 16
percentage = 91.5
is_pass = True

print(student_name, age, percentage, is_pass)
print(type(student_name))
print(type(age))
print(type(percentage))
print(type(is_pass))

Expected Output

Aarav 16 91.5 True <class 'str'> <class 'int'> <class 'float'> <class 'bool'>

Program Explanation

  • student_name = "Aarav" stores a value in student_name.
  • age = 16 stores a value in age.
  • percentage = 91.5 stores a value in percentage.
  • is_pass = True stores a value in is_pass.
  • print(student_name, age, percentage, is_pass) displays information or calculated result on the screen.
  • print(type(student_name)) displays information or calculated result on the screen.
  • print(type(age)) displays information or calculated result on the screen.

Practical Uses

  • Storing names, marks and totals.
  • Checking data type before calculation.
  • Creating forms and reports.

Common Mistakes

  • Writing code with wrong indentation.
  • Using input() value directly in calculations without converting it to int or float.
  • Using unclear variable names that make the program difficult to understand.

Practice Tasks

  1. Program ko variables-data-types.py file me type karke run karein.
  2. Values change karke output compare karein.
  3. storing names, marks and totals par ek छोटा example banayen.
  4. Logic ko apne words me 5 lines me likhein.

सारांश

Variables and Data Types ko tab complete maanenge jab aap iska meaning, example, output aur practical use clearly explain kar saken.

← Back to Python Tutorial