Variables
Introduction to Python
Getting Started
Comments
Variables
Data Types
Type Casting
Input and Output
Operators
Strings
Booleans
Conditional Statements
While Loop
For Loop
Loop Control Statements
Lists
Tuples
Sets
Dictionaries
Functions
Function Arguments and Return Values
Variable Scope
Recursion
Lambda Functions
Arrays and Python Lists
Modules
Dates and Math
String Formatting
File Handling
Try and Except
Classes and Objects
Inheritance
Iterators
JSON
RegEx
Variables
Definition: Variables are names used to store data values. They act as containers for storing data that can be used and changed throughout your program.
Why: Variables are introduced early because almost every programming task involves storing, updating, or retrieving data.
Syntax
variable_name = value
Example
age = 20
city = "Bengaluru"
price = 99.5
print(age)
print(city)
print(price)
Explanation
age,city, andpriceare the variable names.- Python creates a variable automatically the moment you assign a value to it using the
=sign. - A variable can store different types of data, such as whole numbers, decimal numbers, or text strings.
Key Notes
- Variable names should be descriptive (e.g.,
user_ageinstead of justa). - Variable names are case-sensitive (
ageandAgeare different variables). - In Python, you do not need to declare the type of variable; it is determined automatically.
Example
Executing...
❌ Error:
✅ Output:
// Click Run ▶ to execute