0% found this document useful (0 votes)
25 views10 pages

Abuzar Shaiban

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

Abuzar Shaiban

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

Variable

In
Python
What is a Variable in Python?
A Python variable is the name given to a
memory location in a program . In simple
words, we can say that a variable is a
container that contains some information, and
whenever we need that information, we use
the name of that container to access it. Let's
create a variable:
a = 34 # Variable storing an integer
b = 23.2 # Variable storing real number
Here a and b are variables, and we can use a to access 34
and b to access 23.2. We can also overwrite the values in a
and b
Variable Naming Rules in Python
Variable name should start with letter(a to z, A To Z)
or underscore (_).
Valid : age , _age , Age
Invalid : 1age, age-,

 In variable name, no special characters allowed other


than underscore (_).
Valid : age_ , _age
Invalid : age_*,@age, #age
Variable Naming Rules in Python
Variables are case sensitive.
age and Age are different, since variable names are
case sensitive.
age= 25
Print(Age)
it gives error, because age and Age are different.

 Variable name can have numbers but not at the


beginning.
Valid: Age1
Invalid: 1Age
Variable Naming Rules in Python

 Variable name should not be a Python


keyword. Keywords are reserved words in
python.
Example:
pass, break, continue, True, False, in,
and.. etc.
are reserved for special meaning in Python.
So, we should not declare keyword as a
variable name
How to Declare and use a Variable
Let see an example. We will declare variable "a" and print it.

a=100
print (a)

My_age=25
print (My_age)

Num_1=25
print (Num_1)
Re-declare a Variable
You can re-declare the variable even
after you have declared it once.

a=100
print(a)
a=‘AECS Jaduguda’
print(a)
Concatenate Variables
a='AECS'
b=1
print(a+b)
will throw error , as we cannot concatenate two
different datatypes. But
a='AECS'
b=1
print(a+str(b))

Result: AECS1
Delete a variable
You can also delete variable using the
command del "variable name".
a=100
del a
Print(a)

when we proceed to print it, we get error "variable


name is not defined" which means you have deleted
the variable.
Th a
nk Y
ou

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy