1 1-Variables
1 1-Variables
ipynb - Colab
keyboard_arrow_down Variables
Variables are fundamental elements in programming used to store data that can be referenced and manipulated in a program. In Python,
variables are created when you assign a value to them, and they do not need explicit declaration to reserve memory space. The declaration
happens automatically when you assign a value to a variable.
Video Outline:
Introduction to Variables
Declaring and Assigning Variables
Naming Conventions
Understanding Variable Types
Type Checking and Conversion
Dynamic Typing
Practical Examples and Common Errors
a=100
age=32
height=6.1
name="Krish"
is_student=True
print("age :",age)
print("Height:",height)
print("Name:",name)
age : 32
Height: 6.1
Name: Krish
## Naming Conventions
## Variable names should be descriptive
## They must start with a letter or an '_' and contains letter,numbers and underscores
## variables names case sensitive
first_name="KRish"
last_name="Naik"
## case sensitivity
name="Krish"
Name="Naik"
False
print(type(name))
https://colab.research.google.com/drive/1P9cl77QRzUAA0EHlWSawxY6my_vr8dGr#printMode=true 1/3
7/16/24, 7:17 PM 1.1-Variables.ipynb - Colab
<class 'str'>
type(height)
float
age=25
print(type(age))
# Type conversion
age_str=str(age)
print(age_str)
print(type(age_str))
<class 'int'>
25
<class 'str'>
age='25'
print(type(int(age)))
<class 'int'>
name="Krish"
int(name)
height=5.11
type(height)
float
float(int(height))
5.0
## Dynamic Typing
## Python allows the type of a vraible to change as the program executes
var=10 #int
print(var,type(var))
var="Hello"
print(var,type(var))
var=3.14
print(var,type(var))
10 <class 'int'>
Hello <class 'str'>
3.14 <class 'float'>
## input
23 <class 'int'>
https://colab.research.google.com/drive/1P9cl77QRzUAA0EHlWSawxY6my_vr8dGr#printMode=true 2/3
7/16/24, 7:17 PM 1.1-Variables.ipynb - Colab
### Simple calculator
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print("Sum:", sum)
print("Difference:", difference)
print("Product:", product)
print("Quotient:", quotient)
Sum: 66.0
Difference: 46.0
Product: 560.0
Quotient: 5.6
23 <class 'int'>
keyboard_arrow_down Conclusion:
Variables are essential in Python programming for storing and manipulating data. Understanding how to declare, assign, and use variables
effectively is crucial for writing functional and efficient code. Following proper naming conventions and understanding variable types will help in
maintaining readability and consistency in your code.
https://colab.research.google.com/drive/1P9cl77QRzUAA0EHlWSawxY6my_vr8dGr#printMode=true 3/3