0% found this document useful (0 votes)
19 views3 pages

1 1-Variables

Uploaded by

AB
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

1 1-Variables

Uploaded by

AB
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

7/16/24, 7:17 PM 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

add Code add Text


## Declaring And Assigning Variables

age=32
height=6.1
name="Krish"
is_student=True

## printing the variables

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

#valid variable names

first_name="KRish"
last_name="Naik"

# Invalid variable names


#2age=30
#first-name="Krish"
##@name="Krish"

## case sensitivity
name="Krish"
Name="Naik"

False

## Understnading Variable types


## Python is dynamically typed,type of a variable is determined at runtime
age=25 #int
height=6.1 #float
name="KRish" #str
is_student=True #bool

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 Checking and Conversion

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

age=int(input("What is the age"))


print(age,type(age))

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: "))

sum = num1 + num2


difference = num1 - num2
product = num1 * num2
quotient = num1 / num2

print("Sum:", sum)
print("Difference:", difference)
print("Product:", product)
print("Quotient:", quotient)

Sum: 66.0
Difference: 46.0
Product: 560.0
Quotient: 5.6

Start coding or generate with AI.

Start coding or generate with AI.

23 <class 'int'>

Start coding or generate with AI.

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.

Double-click (or enter) to edit

https://colab.research.google.com/drive/1P9cl77QRzUAA0EHlWSawxY6my_vr8dGr#printMode=true 3/3

You might also like