Python program मध्ये data वापरताना त्या data ला meaningful नाव देण्याची गरज असते. त्या नावामुळे आपण value पुन्हा वापरू शकतो, बदलू शकतो आणि program अधिक readable बनवू शकतो. या chapter मध्ये variable म्हणजे काय, variable कसा create करायचा, value assign/reassign कशी करायची, multiple assignment, variable naming rules आणि naming conventions शिकणार आहोत.
या examples साठी Python 3.14 stable series लागू आहे. 7 September 2026 रोजी Python 3.14.7 ही latest stable Python 3 release आहे.
Learning Outcomes#
हा chapter पूर्ण केल्यानंतर तुम्ही independently:
- variable म्हणजे काय हे explain करू शकाल.
- Python मध्ये variable create करून value assign करू शकाल.
- existing variable ची value reassign करू शकाल.
- एकाच statement मध्ये multiple variables assign करू शकाल.
- valid आणि invalid variable names ओळखू शकाल.
- Python चे case-sensitive naming behavior समजू शकाल.
- naming rules आणि naming conventions मधला फरक सांगू शकाल.
- readable
snake_casevariable names लिहू शकाल. - variable-related common syntax आणि runtime mistakes diagnose करू शकाल.
- basic variable interview questions confidently answer करू शकाल.
What is a Variable?#
कल्पना करा की application मध्ये student चे नाव वापरायचे आहे.
आपण प्रत्येक ठिकाणी थेट "Sneha" लिहू शकतो.
print("Sneha")
print("Sneha")
print("Sneha")पण उद्या student चे नाव बदलले तर प्रत्येक ठिकाणी value manually बदलावी लागेल.
याऐवजी:
student_name = "Sneha"
print(student_name)
print(student_name)
print(student_name)आता "Sneha" या value ला आपण student_name हे meaningful नाव दिले आहे.
A variable is a name that refers to a value in a program.
मराठी अर्थVariable म्हणजे program मधील एखाद्या value ला दिलेले नाव.
उदाहरण:
course_name = "Python Beginner Course"इथे:
course_name = "Python Beginner Course"
↓ ↓ ↓
variable name assignment value
operatorमहत्त्वाचे: Beginner level वर variable ला "value ठेवण्याचा box" असे समजणे सोपे वाटू शकते, पण Python मध्ये अधिक अचूक समज अशी आहे:
Variable name एका value/object कडे refer करते.
Python documentation assignment ला name आणि value यांच्यात binding/rebinding म्हणून describe करते.
Why Do We Need Variables?#
Suppose तुम्ही course enrollment system तयार करत आहात.
तुमच्याकडे खालील information आहे:
student_name = "Aarav"
course_name = "Python Beginner Course"
progress = 20आता application मध्ये meaningful names वापरल्यामुळे code लगेच समजतो.
Compare:
x = "Aarav"
y = "Python Beginner Course"
z = 20आणि:
student_name = "Aarav"
course_name = "Python Beginner Course"
progress = 20दुसरा code अधिक readable आहे.
Variables मुळे आपण:
- values ला meaningful names देऊ शकतो
- values पुन्हा वापरू शकतो
- values बदलू शकतो
- code readable ठेवू शकतो
- program state represent करू शकतो
Creating Variables#
A variable is created when a value is assigned to a name.
मराठी अर्थएखाद्या नावाला value assign केली की Python मध्ये त्या नावाचा variable तयार होतो.
Python मध्ये basic variable तयार करण्यासाठी Java सारखी separate declaration आवश्यक नाही.
student_name = "Riya"इथे student_name या नावाला "Riya" value assign झाली.
आता:
print(student_name)Expected Output:
Riyaआणखी examples#
city = "Pune"
experience = 2
course_completed = Falseया chapter मध्ये आपण values चे वेगवेगळे data types खोलात शिकणार नाही. ते Python Data Types chapter मध्ये शिकू.
Variable Creation Flow#
student_name = "Riya"
│
▼
Right-side value is evaluated
│
▼
"Riya"
│
▼
The name student_name is bound to that value
│
▼
student_name can now be usedउदाहरण:
student_name = "Riya"
print(student_name)Assigning Values#
Assignment connects a variable name with a value.
मराठी अर्थAssignment म्हणजे variable च्या नावाला value जोडणे.
Python मध्ये basic assignment साठी = वापरतो.
city = "Mumbai"इथे:
city→ variable name=→ assignment operator"Mumbai"→ assigned value
आणखी example#
employee_name = "Rahul"
employee_id = 105
office = "Pune"
print(employee_name)
print(employee_id)
print(office)Expected Output:
Rahul
105
PuneAssignment करताना Execution Order#
हे statement बघा:
username = "Neha"Conceptually Python:
- right side ची value evaluate करतो
- त्या value ला
usernameनाव bind करतो - त्यानंतर
usernameवापरता येतो
म्हणून:
print(username)हे assignment नंतर valid आहे.
पण:
print(username)
username = "Neha"या वेळी पहिल्या line वर username अजून defined नसेल तर NameError होईल.
Reassigning Values#
Real application मध्ये values नेहमी permanent नसतात.
उदाहरण:
Student ची course progress सुरुवातीला:
progress = 10नंतर:
progress = 40आता progress ची current value 40 आहे.
Reassignment means binding an existing variable name to a new value.
मराठी अर्थExisting variable ला नवीन value assign करणे म्हणजे reassignment.
उदाहरण:
city = "Pune"
print(city)
city = "Mumbai"
print(city)Expected Output:
Pune
Mumbaiकाय झाले?#
Initially:
city ─────► "Pune"
After:
city ─────► "Mumbai"city = "Mumbai" हे statement previous assignment replace करते.
Reassignment in a Real Scenario#
Suppose user ने delivery address change केला.
delivery_city = "Pune"
print(delivery_city)
delivery_city = "Nagpur"
print(delivery_city)Expected Output:
Pune
NagpurApplication च्या current state नुसार variable ची value बदलू शकते.
Same Variable, Different Values#
Python मध्ये variable लिहिताना त्याचा type declare करावा लागत नाही.
उदाहरण:
value = 100
value = "Completed"हे Python मध्ये allowed आहे.
पण values चे types, type checking आणि type() पुढच्या Python Data Types chapter मध्ये detail मध्ये शिकू.
Multiple Assignment#
कधी कधी आपल्याला अनेक variables create करायचे असतात.
Python यासाठी convenient assignment syntax देते.
Assign Different Values to Multiple Variables#
Multiple assignment allows multiple variable names to receive values in one statement.
मराठी अर्थएका statement मध्ये अनेक variables ला values assign करता येतात.
उदाहरण:
name, city, country = "Asha", "Pune", "India"हे conceptually:
name = "Asha"
city = "Pune"
country = "India"यासारखे आहे.
Use:
name, city, country = "Asha", "Pune", "India"
print(name)
print(city)
print(country)Expected Output:
Asha
Pune
IndiaValues position नुसार variables ला assign होतात.
name city country
↑ ↑ ↑
"Asha" "Pune" "India"Assign Same Value to Multiple Variables#
जर अनेक variables ना same value द्यायची असेल:
x = y = z = 0नंतर:
print(x)
print(y)
print(z)Expected Output:
0
0
0हे syntax initialization सारख्या simple cases मध्ये useful असू शकते.
Swapping Two Variables#
Python मध्ये दोन variables च्या values सहज exchange करता येतात.
first = "Tea"
second = "Coffee"
first, second = second, first
print(first)
print(second)Expected Output:
Coffee
TeaBefore:
first → Tea
second → CoffeeAfter:
first → Coffee
second → TeaTemporary variable manually create करण्याची गरज नाही.
Number of Variables and Values Must Match#
हे valid आहे:
x, y = 10, 20पण:
x, y = 10, 20, 30या assignment मध्ये left side वर दोन targets आणि right side वर तीन values आहेत.
Beginner level वर लक्षात ठेवा:
Simple multiple assignment मध्ये variables आणि supplied values योग्य प्रकारे match झाले पाहिजेत.
Advanced unpacking पुढील योग्य chapter मध्ये शिकता येईल.
Variable Naming Rules#
Variable name लिहिण्यासाठी Python चे काही language rules आहेत.
Variable naming rules define which names are syntactically valid Python identifiers.
मराठी अर्थPython मध्ये कोणती variable names technically valid आहेत हे naming rules ठरवतात.
Python identifiers मध्ये letters, underscore आणि digits वापरता येतात; digit पहिल्या character म्हणून वापरता येत नाही. Names case-sensitive आहेत आणि reserved keywords ordinary identifiers म्हणून वापरता येत नाहीत.
Rule 1 — Name Cannot Start With a Digit#
Valid:
student1 = "Amit"
course2 = "Python"Invalid:
1student = "Amit"
2course = "Python"Better:
student1 = "Amit"
course2 = "Python"Rule 2 — Letters, Digits and Underscore Can Be Used#
Valid:
student_name = "Sneha"
student2 = "Rahul"
_score = 80Python technically supports a wider range of Unicode identifiers too, but production code मध्ये simple readable ASCII English names वापरणे beginner साठी अधिक practical आहे.
Rule 3 — Spaces Are Not Allowed Inside a Variable Name#
Invalid:
student name = "Asha"Correct:
student_name = "Asha"Underscore शब्द वेगळे करण्यासाठी useful आहे.
Rule 4 — Hyphen Is Not Used as Part of a Variable Name#
Invalid:
student-name = "Asha"Correct:
student_name = "Asha"- हा variable-name separator नाही.
Rule 5 — Python Keywords Cannot Be Ordinary Variable Names#
Invalid:
class = "Beginner"Invalid:
for = 10class आणि for Python keywords आहेत.
Correct:
course_level = "Beginner"
loop_count = 10Rule 6 — Variable Names Are Case-Sensitive#
हे तीन different names आहेत:
name = "Asha"
Name = "Rahul"
NAME = "Neha"Example:
city = "Pune"
City = "Mumbai"
print(city)
print(City)Expected Output:
Pune
MumbaicityआणिCitysame variable नाहीत.
Rule 7 — Special Symbols Should Not Be Used in Ordinary Variable Names#
Invalid examples:
$user = "Asha"
user@name = "Asha"
total% = 50Use:
user = "Asha"
user_name = "Asha"
total_percentage = 50Naming Rules vs Naming Conventions#
हा distinction खूप important आहे.
Naming Rule#
Rule break केला तर code invalid होऊ शकतो.
2student = "Asha"हे invalid आहे.
Naming Convention#
Convention break केली तरी code run होऊ शकतो, पण code quality कमी होऊ शकते.
उदाहरण:
studentName = "Asha"हे Python मध्ये valid असू शकते.
पण सामान्य Python style:
student_name = "Asha"म्हणून:
Rules decide whether a name is valid. Conventions help make a valid name readable and consistent.
Naming Conventions#
Use snake_case for Normal Variable Names#
snake_case writes lowercase words separated by underscores.
मराठी अर्थअनेक शब्दांच्या variable name मध्ये lowercase words underscore ने वेगळे लिहिण्याची style म्हणजे snake_case.
Examples:
student_name = "Ravi"
course_name = "Python"
total_marks = 450
delivery_city = "Pune"PEP 8 recommends lowercase variable names with underscores between words when needed for readability.
Use Meaningful Names#
Weak:
x = "Python Beginner Course"Better:
course_name = "Python Beginner Course"Weak:
p = 999Better:
course_price = 999Reader ला code समजण्यासाठी guess करावे लागू नये.
Avoid Unnecessarily Long Names#
Too vague:
x = "Pune"Too long:
the_city_where_the_student_currently_lives = "Pune"Better:
student_city = "Pune"Goal:
Clear + concise + meaningful
Avoid Confusing Single-Letter Names#
PEP 8 specifically discourages l, O आणि I single-character names कारण काही fonts मध्ये ते 1 किंवा 0 सारखे दिसू शकतात.
Weak:
l = 10
O = 20
I = 30Better:
length = 10
order_count = 20
item_count = 30Do Not Shadow Important Built-in Names Without a Good Reason#
Python मध्ये काही useful built-in names आहेत.
उदाहरण:
list = "Students"हे काही contexts मध्ये syntactically valid असू शकते, पण आता list नावाचा built-in वापरताना confusion निर्माण होऊ शकतो.
Better:
student_list_name = "Students"Similarly avoid careless names such as:
str = "Hello"
type = "premium"
sum = 100जर तुम्हाला ते built-ins म्हणून नंतर वापरायचे असतील तर अशा naming मुळे problem निर्माण होऊ शकतो.
Constants: UPPER_CASE Convention#
Python language normal variables सारखीच assignment वापरते, पण project मध्ये "ही value बदलू नये" असा developer intent दाखवण्यासाठी constants साठी uppercase convention वापरली जाते.
MAX_ATTEMPTS = 3
DEFAULT_LANGUAGE = "Marathi"हा language enforcement rule नाही; ही naming convention आहे.
Practical / Real-World Application#
Scenario: Course Enrollment#
Suppose तुम्ही online learning application बनवत आहात.
New enrollment साठी:
student_name = "Sneha"
course_name = "Python Beginner Course"
course_status = "Not Started"
progress = 0User course सुरू करतो.
course_status = "In Progress"
progress = 15Complete example:
student_name = "Sneha"
course_name = "Python Beginner Course"
course_status = "Not Started"
progress = 0
print(student_name)
print(course_name)
print(course_status)
print(progress)
course_status = "In Progress"
progress = 15
print(course_status)
print(progress)Expected Output:
Sneha
Python Beginner Course
Not Started
0
In Progress
15इथे आपण:
- meaningful variables तयार केले
- initial values assign केल्या
- बदललेली application state reassign केली
- consistent naming convention वापरली
Another Practical Example: Delivery Details#
customer_name = "Rohan"
delivery_city = "Pune"
delivery_status = "Pending"
print(customer_name)
print(delivery_city)
print(delivery_status)
delivery_city = "Mumbai"
delivery_status = "Confirmed"
print(delivery_city)
print(delivery_status)Expected Output:
Rohan
Pune
Pending
Mumbai
Confirmedयामुळे variable फक्त academic concept नसून application state represent करण्यासाठी fundamental आहे हे दिसते.
Common Mistakes & Misconceptions#
Misconception 1 — "Variable म्हणजे permanently fixed value"#
का believable वाटते?
कारण आपण variable create करताना एक value assign करतो.
पण:
status = "Pending"
status = "Completed"Correct understanding:
Variable name पुन्हा दुसऱ्या value ला bind होऊ शकते.
Misconception 2 — "= म्हणजे mathematical equality"#
Programming assignment मध्ये:
score = 100याचा अर्थ:
scoreला100assign करा.
हे mathematical equation solve करणे नाही.
Comparison operations आपण appropriate पुढील chapter मध्ये शिकू.
Misconception 3 — "Variable वापरण्याआधी declaration line आवश्यक आहे"#
Python basic assignment मध्ये:
name = "Asha"हेच name create/bind करण्यासाठी पुरेसे आहे.
Separate:
declare nameअशी ordinary beginner syntax नाही.
Misconception 4 — "userName invalid आहे कारण Python snake_case वापरतो"#
userName syntax च्या दृष्टीने valid असू शकते.
पण:
user_nameहे Python naming convention ला अधिक consistent आहे.
Rule आणि convention confuse करू नका.
Misconception 5 — name आणि Name Same आहेत#
Wrong.
name = "Riya"
Name = "Aarav"हे दोन वेगळे identifiers आहेत.
Misconception 6 — कोणतेही readable word variable म्हणून वापरता येते#
नाही.
class = "Python"class reserved keyword असल्यामुळे ordinary variable name म्हणून वापरता येत नाही.
Hands-On Practice#
Practice 1 — Create Meaningful Variables#
Requirement#
खालील student information variables मध्ये store करा:
- name = Anaya
- city = Pune
- course = Python
Learner Task#
Meaningful snake_case names वापरा आणि values print करा.
Hint 1#
Assignment syntax:
variable_name = valueHint 2#
तीन separate variables create करा.
Solution#
student_name = "Anaya"
student_city = "Pune"
course_name = "Python"
print(student_name)
print(student_city)
print(course_name)Expected Output:
Anaya
Pune
PythonPractice 2 — Reassign a Status#
Requirement#
Initial order status "Pending" आहे. नंतर ते "Shipped" करा.
Learner Task#
एकच variable वापरा.
Hint#
Existing name ला पुन्हा value assign करा.
Solution#
order_status = "Pending"
print(order_status)
order_status = "Shipped"
print(order_status)Expected Output:
Pending
ShippedPractice 3 — Multiple Assignment#
Requirement#
एका statement मध्ये:
name="Ravi"city="Nagpur"country="India"
assign करा.
Solution#
name, city, country = "Ravi", "Nagpur", "India"
print(name)
print(city)
print(country)Practice 4 — Find Invalid Names#
खालील names classify करा:
student_name
2student
student2
student-name
class
StudentNameSolution#
| Name | Syntax Valid? | Comment |
|---|---|---|
student_name | Yes | Recommended style |
2student | No | Starts with digit |
student2 | Yes | Digit after first character is allowed |
student-name | No as one identifier | Hyphen is not part of a normal identifier |
class | No | Python keyword |
StudentName | Yes | Valid, but not preferred style for normal variables |
Practice 5 — Improve Naming Quality#
Rewrite:
n = "Aarav"
c = "Python Beginner Course"
p = 999Solution#
student_name = "Aarav"
course_name = "Python Beginner Course"
course_price = 999Why better?
Reader ला प्रत्येक value चा purpose लगेच समजतो.
Interview Preparation#
1. What is a variable in Python?
A variable is a name that refers to a value or object in a Python program.
What the interviewer is testing: Whether you understand that a Python variable is a name bound to a value rather than a permanently typed storage box.
2. How do you create a variable in Python?
A variable is created by assigning a value to a name.
student_name = "Asha"Python does not require a separate declaration for ordinary variables before assignment.
3. What is variable assignment?
Variable assignment binds a name to a value using the assignment operator =.
score = 100Here, the name score refers to the assigned value.
4. What is reassignment?
Reassignment means assigning a new value to an existing variable name.
status = "Pending"
status = "Completed"After the second assignment, status refers to "Completed".
5. Can a Python variable be assigned a different kind of value later?
Yes.
value = 10
value = "Done"Python does not require a fixed type declaration for an ordinary variable name.
A detailed discussion of Python data types belongs to the data-types topic.
6. What are the basic rules for naming variables in Python?
A variable name:
- cannot start with a digit
- can contain letters, digits and underscores
- cannot be a Python reserved keyword
- is case-sensitive
- cannot contain spaces as part of one identifier
Python also supports valid Unicode identifiers, although simple ASCII names are commonly preferred for broad readability.
7. Are name, Name, and NAME the same variable?
No. Python identifiers are case-sensitive, so these are three different names.
8. What is the difference between a naming rule and a naming convention?
A naming rule determines whether an identifier is syntactically valid.
A naming convention is a style recommendation that improves consistency and readability.
For example:
2student = "Asha"is invalid because it breaks a language rule.
studentName = "Asha"can be valid, but:
student_name = "Asha"better follows standard Python variable naming style.
9. What naming convention is normally used for Python variables?
Python variables normally use lowercase words separated by underscores when necessary.
Example:
student_name = "Asha"This style is commonly called snake_case.
10. What is multiple assignment in Python?
Multiple assignment allows multiple names to receive values in a single assignment statement.
x, y = 10, 20Here, x receives 10 and y receives 20.
11. How can you assign the same value to multiple variables?
You can use chained assignment:
x = y = z = 0All three names are bound to the assigned value.
12. How can two variable values be swapped in Python?
Python supports direct swapping:
first, second = second, firstA separate temporary variable is not required.
13. What happens if you use a variable before assigning it?
If the name cannot be resolved, Python raises a NameError.
Example:
print(score)If score has not been defined in the applicable scope, the statement fails.
14. Why are meaningful variable names important?
Meaningful names improve readability, maintainability, debugging and communication between developers.
For example:
course_price = 999communicates more intent than:
p = 999Quick Revision#
- Variable म्हणजे value/object कडे refer करणारे नाव.
- Basic assignment:
name = "Asha"- Reassignment:
status = "Pending"
status = "Completed"- Different values:
x, y = 10, 20- Same value:
x = y = z = 0- Swap:
x, y = y, x- Variable name digit ने सुरू करू नका.
- spaces आणि normal identifier मध्ये hyphen वापरू नका.
- Python keywords variable names म्हणून वापरू नका.
- Names case-sensitive आहेत.
- Normal variables साठी
snake_caseprefer करा. - Meaningful, concise names वापरा.
- Naming rule आणि naming convention वेगळे आहेत.
- Variable वापरण्यापूर्वी त्याला value assign झालेली असणे आवश्यक आहे.
You Should Now Be Able To#
आता तुम्ही:
- Python variable explain करू शकता.
- basic assignment लिहू शकता.
- variable ची value reassign करू शकता.
- multiple assignment वापरू शकता.
- same value multiple names ला assign करू शकता.
- two values swap करू शकता.
- valid/invalid identifiers ओळखू शकता.
- case sensitivity explain करू शकता.
- keywords चुकीने variable names म्हणून वापरणे टाळू शकता.
- snake_case variable names लिहू शकता.
- unclear variable names improve करू शकता.
- basic variable bugs diagnose करू शकता.
- beginner-level Variables interview questions answer करू शकता.
Final Challenge#
Scenario#
तुम्ही simple course-registration program चा data तयार करत आहात.
Initial information:
Student: Meera
Course: Python Beginner Course
Status: Registered
City: Puneनंतर:
Status becomes Active
City changes to MumbaiConstraints#
- Meaningful
snake_casenames वापरा. - Initial values assign करा.
- Status आणि city reassign करा.
student_nameआणिcourse_nameएकाच statement मध्ये assign करण्याचा प्रयत्न करा.- Final values print करा.
Hint 1#
a, b = value1, value2Hint 2#
Existing variable update करण्यासाठी त्याच नावाला नवीन value assign करा.
Solution#
student_name, course_name = "Meera", "Python Beginner Course"
registration_status = "Registered"
student_city = "Pune"
registration_status = "Active"
student_city = "Mumbai"
print(student_name)
print(course_name)
print(registration_status)
print(student_city)Expected Output:
Meera
Python Beginner Course
Active
MumbaiReasoning#
या challenge मध्ये तुम्ही:
- variable creation
- assignment
- multiple assignment
- reassignment
- meaningful naming
- snake_case
हे chapter मधील core concepts एकत्र वापरले.