1/28/2021 Python for O&G Lecture 4 - Variables - Colaboratory
Python for Oil and Gas
Website - https://petroleumfromscratchin.wordpress.com/
LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch
YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw
Variables are used for storing data values!
# examples of variables
a = 5
b = 7
print(a)
print(b)
/
1/28/2021 Python for O&G Lecture 4 - Variables - Colaboratory
5
7
print(a+b)
12
print(a*b)
35
# you can update the variables
a = 9
b =568745161
print(a)
print(b)
568745161
We can store any data type in a variable
c = 2.56
d = 3+9j
print(c+d)
(5.5600000000000005+9j)
/
1/28/2021 Python for O&G Lecture 4 - Variables - Colaboratory
e = 'Divyansh'
print(e)
Divyansh
Rules for Variable Names
1. Variable always start with a letter or an underscore
2. Variable name only contains alphabets, numeric values and underscore
3. Variable name never starts with a number
4. Variable names are case sensitive
abc = 'random'
_abc = 'kjsdkjb'
1abc = 'jnckj'
File "<ipython-input-11-594ed4ed1e92>", line 1
1abc = 'jnckj'
^
SyntaxError: invalid syntax
SEARCH STACK OVERFLOW
_bh23 = 'rJKNSKJB'
_bh23$ = 59
/
1/28/2021 Python for O&G Lecture 4 - Variables - Colaboratory
File "<ipython-input-13-dc7e7b0dbd1f>", line 1
_bh23$ = 59
^
SyntaxError: invalid syntax
SEARCH STACK OVERFLOW
var = 15
Var = 60
print(var)
15
print(Var)
60
print(var + Var)
75
/
1/28/2021 Python for O&G Lecture 4 - Variables - Colaboratory