Dec 07-11, 2020 Vikrant Patil
These notes are available online at http://notes.pipal.in/2020/arcesium_finop_batch3/module1-day1.html
© Pipal Academy LLP
Day 1 | Day 2 | Day 3 | Day 4 | Day 5
We will be using jupyter hub from http://lab.pipal.in for this training.
esc + m -> covert the cell to markdown
esc +y -> convert back the cell to code cell
shift + enter -> execute the cell
# Header1
## Header2
### Header3
2 + 3
simply type text
42 + 0
if you run command python from windows cmd/unix terminal, mac terminal
Python 3.8.3 (default, Jul 2 2020, 16:21:59)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
3 + 4
42 + 42 # text after # is comment
42 - 42
42 * 2
5 /2 # real number division
5 // 2 # integer division
2 ** 5 # raise to power
5 % 2 # remainder when 5 divided by 2
1.1 + 1.1
1.0 - 1.0
1.0 * 2
5.0 / 2
5.0 // 2
2.0 ** 5
These symbols are called as operators. And these operators have some priorities when you face multiple operators in single statement.
2**5%5/2*7
Priority table for operators
============= ===========
operators priorities
============= ===========
** 1
% // / * 2
+ - 3
============= ===========
2**5%5/2*7
32%5/2*7
2/2*7
1.0*7
7.0
2**(5%5)/2*7 # with brackets you can change the priority
3*2 # integer * integer => integer
3*2.0 # integer * float => float
4/2 # division results in float by default
4//2 ## if you want integer then you must give explicitly integer division
7 + 2 *3
(7+2)*3
Now we know wokring with numbers/numeric data , lets work with text data
"Hello this text data"
'Hello, this is also text data!'
"""line one
line two
line three
line four"""
2
'''
one
two
three
four
'''
"""
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
"""
"text\ntext1\ntext2"
"Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!"
Question: What will happen if I put multiline text in single(not tripple) quotes!
'''
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
'''
"hello\ttest"
2 * 3
"this is number 2, this is tab \t"
"hello" + " world" # + operator results in concatenation of strings/text
"*" * 5 # operator * results in repeating the string 5 times
"-"*10
3
"3"
"type any thing with any quote , single quote will come"
10.5*"5"
"hello"*5
"hello"*"hello" #it won't allow multiplication with any random thing... only with integers it will allow multiplication
"text"*3
"text"*3.0
"text"*"hello"
"hello" + "world" # only text can be added in a text
"hello" + 3
"hello" + "3"
Problems:
P(1+r/n)**(nt). In this this formula,P is the principal amount, r is the rate of interest per annum, n denotes the number of times in a year the interest is compounded. and t denotes the number of years of investment.Use python to compute totol amount for principle 26780, rate of interest 7%, interest is compounded quarterly and amount is invested for 5 years. 2 + 3
39455.5 * 90.4 # here 90.4 is currency conversion rate
# P(1+r/n)**(nt)
2(2+3)
2*(2+3)
# P(1+r/n)**(nt)
26780*(1+(7/100)/4)**(4*5)
In addition to arithmatic operators there is something called as = assignment operator
x = 10 # it has actually stored value 10 in something with name x, which can be used later
x + 2
P = 26780
r = 7/100
n = 4
t = 5
P*(1+r/n)**(n*t)
x = 155
y = 100 # to see this variable later I must execute this cell everytime I do a change
z = 500
x
155 # this is called a litteral
x + y
z
x
y
z
z
z # before this line I made a change in a cell where z is defined... then I excuted that cell... then only I can see change here
155 # is litteral
x = 155 # is variable
x
Now look at litteral in context of text data
vikrant = 10
"vikrant" # this is litteral
vikrant # this is variable
s = "some value" # a variable is created through assugnement operator
2 = "hello" # you can't create a variable of any name that you wish
What can be used as variable name?
[a-z][A-Z], digits[0-9] and underscorea = 2
b = 3
a, b = 2, 3 # you can create as many variable as possible in single = operator
x,y,z = 0,0,0
r,g,b = 255,0,0
Problems: Have a look at following python statements.
x = 10
y = x
x = x + 10
What will be value of y after this?
x = 10
y = x
x = x+10
y
x
Problem:
x = 10
y = x
y = 25
what will be the value of x after this?
x = 10
y = x
y = 25
x
s = "hello"
s
s[0] # square bracket and inside that some integer value
s[4]
s[1]
s[0] # index starts at 0
s[-1] # last
s[-2] # second last
s[4]
s[5] # we have tried access beyond the string limit
p = "python"
+---+---+---+---+---+---+
| p | y | t | h | o | n |
+---+---+---+---+---+---+
0 1 2 3 4 5 --->
-6 -5 -4 -3 -2 -1 <----
[1, 1, 1] # list .. which has stored 1 ,1 ,1 in it
ones = [1, 1, 1, 1]
ones
numbers = [1, 2, 3, 4]
words = ["these", "are", "some", "words"]
words
mixed = ["python", "solves", 42, 0]
name = "vikrant"
name
words
numbers
print(words)
name ## reprentative repsonse of interpeter
print(name) # this is print
name[0]
print("hello")
mixed
nested = [[1, 2, 3], [2, 3, 4]]
words
words[0] # zeroth word
words[-1] # last word
words[5]
x = 10
words
words[0] = "first"
words
words[-1] = "last"
words
name
name[0]
name[0] = "V" # immutable object...once created can not be changed
"hello " + name
ones
ones * 2 # just like string it suports * and + operator
ones2 = ones*2
ones2
ones
fivestar = "*"*5
fivestar
zeros = [0, 0 , 0]
oneszeros = ones + zeros
oneszeros
m = ones+ zeros
m
Tuples
Siblings of list
color = (0, 0, 255) # tuple is created with ()/ list is created with []
color[0] # access of element from tuple is similar to list
color[-1]
color[2]
color * 2
(1, 1, 1) + (0, 0, 0)
color
color[2] = 0 # tuple is also immutable object , once created can not be modified
color
color[0]
color[0] = 255
color = (255, 0, 0) # rbg
blue = (0, 0, 255)
red = (255, 0, 0)
color = blue
color
color = red
color
red[2]=10
purple = (255, 0, 15)
purple
purple[2] = 50
purple = (255, 0, 50)
words[0]="zero"
words
student = ['nishant','shivam','sachin']
student[0]
student[2]
emails = {"nishant":"nishant@xyz.com",
"sachin":"sachin@xyz.com",
"vikrant":"vikrant@xyz.com"} # curly brackets
emails
ages = {"alice":13,
"alex":5,
"maya":23}
ages
emails['nishant'] # you give name/key instead of number
ages['alice']
ages['alice'] = 14
ages
stock = {"name":"IBM",
"open":123,
"close":125,
"high":126,
"low":120.4}
stock
stock['name']
stock['close'] # you can access only by name/key not by position or index
stock["close"]
nums = {1:"one",
2:"two"}
True
False
x == 10
multiline = """
line one
line two
line three
"""
multiline
print(multiline)
homework = {"poem":"""
my poem
line 1
line 2
line3
"""}
homework['poem']
stock1 = {"name":"IBM", "open":123}
stock1 = {"name":"IBM",
"open":123}
matrix = [
[1, 1, 1],
[2, 2, 2],
[3, 3, 3]
]
matrix
mat = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
l = [23, 343 , "helllo"]
bignames = ["fkjdhsf dhfdkjs hfkjhdsfkjhds kjfhdskjfh dhf",
"kjdshf kjdhfkjdshf lkdjflkjds lkdsjflkjdsf ",
"dsjfgdshfg jdjgfdg dsjfgdshgf djgf gdjfghdsg f"]
bignames[0]
t = (
"this is my first item from tuple",
2,
"This is last item from tuple"
)
t[0]
Those who do not have python installed on your system. go this site and download appropriate python executable installer and install it on your system.