Jun 20-24, 2022 Vikrant Patil
All notes are available online at https://notes.pipal.in/2022/arcesium_finop_batch1/
Please accept the invitation that you have received in your email and login to
© Pipal Academy LLP
multiply two and five and write down result in your notebook!
2*3
6
If you try to type notes in this
Input In [2] If you try to type notes in this ^ SyntaxError: invalid syntax
| keys | action |
|---|---|
| esc+m | convert the cell into markdown cell |
| esc+y | cpnvert the cell into code cell |
| shift+enter | execute current cell |
| esp+b | insert new cell after current cell |
| !command | execute system command |
Very way primitive way of programming is manipulating numbers and text. To manipulate numbers python has got basic numeric capabilities.
integers
42 + 42
84
42 - 42
0
42 / 2
21.0
42**2 # comment ..** is for power
1764
2**5
32
5 % 2 # modulus operator
1
5 // 2
2
42 // 2
21
Numeric data in python has two forms ..integers and floats
float
1.1 + 1.1
2.2
1 + 1.1 # it results in float
2.1
5.0 * 3
15.0
5.0 / 2.0
2.5
5.0 // 2.0
2.0
2.0 ** 5
32.0
2**5
32
100**5
10000000000
There is certain priority about the mathematical operation, which will be executed first!
2 + 3*5 # this means * has higher priority
17
2 + 2**5
34
3 * 2**5 # among * and ** , ** has higher priority
96
2**5%5/2*7
32%5/2*7
2/2*7
1*7
7
| operator | priority |
|---|---|
** |
1 |
% // / * |
2 |
+ - |
3 |
And if we want to change the priority, then we make use of braces to make sure that relevant part is executed first
7 + 2 * 3
13
(7+2)*8
72
string
"Hello, this is text data"
'Hello, this is text data'
2
2
'text'
'text'
"text"
'text'
"text"*2
'texttext'
"ten"*10
'tentententententententententen'
"first" + "second"
'firstsecond'
"vikrant" + "patil"
'vikrantpatil'
"vikrant" - "vikr" # it does not supprt substraction
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Input In [35], in <cell line: 1>() ----> 1 "vikrant" - "vikr" TypeError: unsupported operand type(s) for -: 'str' and 'str'
"*"*50
'**************************************************'
As told earlier python is higher level language. i.e it is very close to english, human language! So python can write poems
"""The Zen of Python, by Tim Peters
Beautiful is better than ugly
Explicit is better than implicit
Simple beteer than complex
"""
'The Zen of Python, by Tim Peters\n\nBeautiful is better than ugly\nExplicit is better than implicit\nSimple beteer than complex\n'
'''Flat is better than nested
Sparse is better than dense
Redability counts'''
'Flat is better than nested\nSparse is better than dense\nRedability counts'
"text\thello"
'text\thello'
problems
20345.5*86.66
1763141.03
2(3+4)
<>:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma? <>:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma? /tmp/ipykernel_3772/679493015.py:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma? 2(3+4) /tmp/ipykernel_3772/679493015.py:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma? 2(3+4) /tmp/ipykernel_3772/679493015.py:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma? 2(3+4)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Input In [42], in <cell line: 1>() ----> 1 2(3+4) TypeError: 'int' object is not callable
2*(3+4)
14
26780*(1+0.07/4)**(5*4)
37887.76008234032
2 # integer ....literally 2!!
2
45 # this is called literal
45
x = 10 # = is called as assignment operator
x # interpreter reponds back with what x is pointing to! or what is stored inside x!
10
P = 50000
r = 0.07
t = 4
n = 5
P*(1+r/t)**(n*t)
70738.90978778999
x,P,r,t, and n are called as variables
26780 # just a literal
26780
"hello" # literal string
'hello'
greeting = "hello"
greeting # is a variable
'hello'
ten = 10 # is a variable
"ten" # is not a variable
'ten'
ten
10
"ten"
'ten'
Q: What can be used as a variable?
2 = 5
Input In [70] 2 = 5 ^ SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?
- = 5
Input In [71] - = 5 ^ SyntaxError: invalid syntax
test = 54
test232 = 3434
y-z = 5
Input In [74] y-z = 5 ^ SyntaxError: cannot assign to expression here. Maybe you meant '==' instead of '='?
greet_hello = "hello"
Rules
a = 54
a,b = 2,3
a
2
b
3
Problem
Have a look at following statements. what will be value of y after thi
x = 10
y = x
x = x + 10
y
10
x = 10
y = x
y = 25
What will be value of x after this?
x
10
Lets work with text data that we have variables
s = "hello"
s[0] # first item from the text data .. in python first starts at zero
'h'
s[4] # item (charecter) at forth index
'o'
s[-1] # last element!
'o'
The indices work like this in python
+---+---+---+---+---+---+
| P | y | t | h | o | n |
+---+---+---+---+---+---+
->0 1 2 3 4 5
-6 -5 -4 -3 -2 -1 <-
p = "Python"
p[0]
'P'
p[1]
'y'
p[-1]
'n'
p[-6]
'P'
p[100]
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) Input In [97], in <cell line: 1>() ----> 1 p[100] IndexError: string index out of range
p[-7]
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) Input In [99], in <cell line: 1>() ----> 1 p[-7] IndexError: string index out of range
Collection of basic data into some format of array or column or row...
list
[1, 1, 1] # this is list of three 1s
[1, 1, 1]
ones = [1, 1, 1, 1]
ones[0] # indexing works just like text data
1
nums = [1, 2, 3, 4, 5]
nums[0]
1
nums[-1]
5
words = ["hello", "howdy", "welcome", "hiee"]
words[0]
'hello'
words[-1]
'hiee'
words
['hello', 'howdy', 'welcome', 'hiee']
ones
[1, 1, 1, 1]
nums
[1, 2, 3, 4, 5]
mixed = [5, 2, "one", "two" , "hello"]
mixed
[5, 2, 'one', 'two', 'hello']
mixed[0]
5
mixed[1]
2
mixed[3]
'two'
matrix = [[1, 2, 3],[4,5,6],[7,8,9]]
matrix
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
matrix[0]
[1, 2, 3]
matrix[1]
[4, 5, 6]
matrix[2]
[7, 8, 9]
matrix[0][0]
1
matrix[1][2]
6
matrix[2][2]
9
matrix[-1][-1]
9
words
['hello', 'howdy', 'welcome', 'hiee']
"hello" + "welcome"
'hellowelcome'
words + nums # it concatenates
['hello', 'howdy', 'welcome', 'hiee', 1, 2, 3, 4, 5]
words*2 # repeates the list two times
['hello', 'howdy', 'welcome', 'hiee', 'hello', 'howdy', 'welcome', 'hiee']
words
['hello', 'howdy', 'welcome', 'hiee']
problem can you create a list with 100 ones in it?
one = [1]
ones_100 = one*100 # this will have 100 ones in it
words
['hello', 'howdy', 'welcome', 'hiee']
words[0]
'hello'
words[0] = "HELLO"
words
['HELLO', 'howdy', 'welcome', 'hiee']
words[-1] = "Hi"
words
['HELLO', 'howdy', 'welcome', 'Hi']
tuple
color = (0, 0, 256) # instaed if square bracket we use round bracket
color*2
(0, 0, 256, 0, 0, 256)
color + color # concatenates
(0, 0, 256, 0, 0, 256)
color[0]
0
color[-1]
256
color[0] = 255
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Input In [153], in <cell line: 1>() ----> 1 color[0] = 255 TypeError: 'tuple' object does not support item assignment
tuple is immutable object! that means something that is once created can not be modified
dictionary
is collection of key and value pairs. Keys have to be uniue. Values need not be unique.
score = {"Sachin": 20,
"Sanskruti": 23,
"Shila": 20,
"Vedant":22,
"Tom": 21}
score['Tom']
21
score['Vedant']
22
stock = {"Name":"IBM", "value":123, "count": 250}
stock['Name']
'IBM'
stock['value']
123
Boolean
True
True
False
False
None
None
"" # empty string
''
[] # empty list
[]
name = "Rupali"
len(name) # len is a function which is getting called in this statement with a parameter name
6
2()
<>:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma? <>:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma? /tmp/ipykernel_3772/1017438639.py:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma? 2() /tmp/ipykernel_3772/1017438639.py:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma? 2() /tmp/ipykernel_3772/1017438639.py:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma? 2()
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Input In [170], in <cell line: 1>() ----> 1 2() TypeError: 'int' object is not callable
nums
[1, 2, 3, 4, 5]
len(nums)
5
len(words)
4
len([1]*100)
100
stock
{'Name': 'IBM', 'value': 123, 'count': 250}
len(stock)
3
"23" # this is text not a number
'23'
"23"*2 # will not work as a mathematical statement
'2323'
int("23")*2
46
int("343543")
343543
int("test")
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Input In [183], in <cell line: 1>() ----> 1 int("test") ValueError: invalid literal for int() with base 10: 'test'
int("2.3")
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Input In [184], in <cell line: 1>() ----> 1 int("2.3") ValueError: invalid literal for int() with base 10: '2.3'
int(2.3)
2
str(2312132432432)
'2312132432432'
!ls
index.html index.ipynb Makefile module1-day1.html module1-day1.ipynb push