0% found this document useful (0 votes)
4 views5 pages

Python Session 1 Variables

Uploaded by

ameen1ahmad06
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)
4 views5 pages

Python Session 1 Variables

Uploaded by

ameen1ahmad06
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/ 5

Variable

Storing a value

Variable can change the values also

In [8]: number2=100
# 100 is stored in a variable called **number**

# number1=100
# i excecuted

In [12]: number2

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[12], line 1
----> 1 number2

NameError: name 'number2' is not defined

In [ ]: number=200

In [16]: omkar=200

In [18]: omkar

Out[18]: 200

Name error

Name error occures when we are using the variable with out define

Or we are using before define

Make sure you should define the variable first

If you feel you alreday defined , run the define cell again

and print the answer

In [21]: number1=100 # 100 rupees in number1


number1=200 # 200 rupees in number1
number1

Out[21]: 200

In [23]: # Python is a step by step process


n1=100 # 100 stored in n1
n2=200 # 200 stored in n2
n1 # 100
n2 # 200
Out[23]: 200

In [25]: n1=100
n2=200
print(n1)
print(n2)

100
200

In [27]: n1

Out[27]: 100

In [29]: n2

Out[29]: 200

In [31]: n1,n2

Out[31]: (100, 200)

In [ ]: n1=100 # works
n2=200 # works
n1,n2=100,200 # works
n1=100,200 # works
n1,n2=100 # fail

In [ ]: number1=100
NUMBER1=200
NUMber=300
number123=400

In [33]: NUMBER1=200
print(NUMBER1)

200

In [35]: NUMber=300
print(NUMber)

300

In [37]: print(NUMber=300) # wrong

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[37], line 1
----> 1 print(NUMber=300)

TypeError: 'NUMber' is an invalid keyword argument for print()

In [ ]: number1=100
NUMBER1=200
NUMber=300
number123=400
123number=500 # fail

In [39]: 123number=500
Cell In[39], line 1
123number=500
^
SyntaxError: invalid decimal literal

In [ ]: number1=100
NUMBER1=200
NUMber=300
number123=400
123number=500 # fail
number%=600 # fail
number$=700 # fail
number_=800 # works

In [41]: number_=800

In [43]: number$=700

Cell In[43], line 1


number$=700
^
SyntaxError: invalid syntax

In [49]: areaofcircle=10
print(areaofcircle)

area_of_circle

n1=100

10
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[49], line 3
1 areaofcircle=10
2 print(areaofcircle)
----> 3 area_of_circle
4 n1=100

NameError: name 'area_of_circle' is not defined

In [ ]: number1=100
NUMBER1=200
NUMber=300
number123=400
123number=500 # fail
number%=600 # fail
number$=700 # fail
number_=800 # works
_=900 # works
1000=n # fail
10=10 # fail
10==10

In [51]: 10==10
Out[51]: True

In [ ]: # = assign
# == compare

In [53]: number%=600

In [55]: sum=900
sum

Out[55]: 900

In [1]: sum([1,2,3,4])

Out[1]: 10

In [5]: number=1000
number%=600

In [ ]: number1=100
NUMBER1=200
NUMber=300
number123=400
123number=500 # fail
number%=600 # fail
number$=700 # fail
number_=800 # works
_=900 # works
1000=n # fail
10=10 # fail
10==10
sum=100 # inbuilt function we should not use
if=1000

In [ ]: True
False
if
else
elif
for
while

Variables are Case sensitive

Numbers as prefix should not use as varaibel ex: 123number

Spl characters are not allowed ex: number$, number&

Keywords and inbuilt functions should not use as variable ex: if min max sum

only underscore allowed

In [9]: sum([1,2,3,4])
Out[9]: 10

In [17]: import os
os.getcwd()

Out[17]: 'C:\\Users\\omkar\\OneDrive\\Documents\\Data science\\Naresh IT\\Naresh IT\\Dat


a science\\Batches\\Batch-15_May\\Python_Sessions'

In [ ]:

You might also like