3 + 47
In markdown cell I can type notes for my reference. This all can be done within the program
=========== ====================================
keys action
=========== ====================================
esc+m convert the cell to markdown
esc+y convert the cell to code
shift+enter execute the cell
!command execute system command from jupyter
=========== ====================================
the colon and square brackets will not be there for markdown cell!
3 + 4
These charecters are special . they are called as operators. Operator needs two items on its boths sides. left and and right hand side
+ - * / // **
Can I have multiple operators in one line?
yes
============ ========
operators priority
============ ========
``**`` 1
``% // / *`` 2
``+ -`` 3
============ ========
Problem
Compound interest is computed using this formula \(P (1 + r/n)^{nt}\)
P Pinciple = 26780
r rate of interest = 0.07
n number of times interest is compunded in a year = 4
t number of years = 5
<>: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_115462/3832789996.py:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma?
2(1 + 3) # python does not understand this
/tmp/ipykernel_115462/3832789996.py:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma?
2(1 + 3) # python does not understand this
/tmp/ipykernel_115462/3832789996.py:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma?
2(1 + 3) # python does not understand this
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[23], line 1 ----> 1 2(1 + 3) # python does not understand this TypeError: 'int' object is not callable
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[36], line 1 ----> 1 1 + "st" # on both sides there are data types which are compatible for addition! TypeError: unsupported operand type(s) for +: 'int' and 'str'
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[41], line 1 ----> 1 1 + "st" TypeError: unsupported operand type(s) for +: 'int' and 'str'
There is another operator called =. This operator allows us to create variables
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[55], line 1 ----> 1 a NameError: name 'a' is not defined
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[56], line 1 ----> 1 X*2 NameError: name 'X' is not defined
Cell In[66], line 2 10 -> literal value of one int ^ SyntaxError: invalid syntax
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[87], line 1 ----> 1 del X,Y NameError: name 'X' is not defined
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[86], line 1 ----> 1 X NameError: name 'X' is not defined
Problem
X = 10
Y = X
X = X + 10
What will be value of Y?
Problem
What will be value of x after executing all statements?
x = 10
y = x
y = 25
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) Cell In[103], line 1 ----> 1 text[10] IndexError: string index out of range
+---+---+---+---+---+---+
| P | y | t | h | o | n |
+---+---+---+---+---+---+
-> 0 1 2 3 4 5
-6 -5 -4 -3 -2 -1 <-
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[120], line 1 ----> 1 mixed(2) # round bracket has different meaning TypeError: 'list' object is not callable
list can have anything in it
[[1, 2, 3, 4, 5],
['one', 'two', 'three', 'four'],
['one', 1, 'two', 3847623, 3.5],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1]]
words[1,3] # to access element from list/string in square bracket only one valid index has to be given! --------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[148], line 1 ----> 1 words[1,3] # to access element from list/string in square bracket only one valid index has to be given! TypeError: list indices must be integers or slices, not tuple
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[150], line 1 ----> 1 words(2) # sqaure brackets are needed TypeError: 'list' object is not callable
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[152], line 1 ----> 1 x[0] # sqaure bracket can be given only after text/list TypeError: 'int' object is not subscriptable
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[168], line 1 ----> 1 text[-1] = "N" TypeError: 'str' object does not support item assignment
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[180], line 1 ----> 1 yetanother_textlist[0][-1] = "N" TypeError: 'str' object does not support item assignment
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
in dictionary we save name and value pairs. So that we can retrive values with name instead of index (as in list)
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) Cell In[198], line 1 ----> 1 person['country'] KeyError: 'country'
What keys and values are possible?
tuples are similar to lists, but they can not be modified once created
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[207], line 1 ----> 1 color[0] = 255 TypeError: 'tuple' object does not support item assignment
to make a list we make use square brackets []
to make a string we make use of single or double quotes
to make a tuple we make use of round brackets ()
to make a dictionary we make use of curley brackets {}, inside you have to give key:value pairs separated by comma
to access item from a string we use square bracket and integer index inside that string[2]
to access item from a list we use square bracket and integer index inside that list[2]
to access item from a tuple we use square bracket and integer index inside that tuple[2]
to access item from a dictionary we use square bracket and key inside that d[‘key’]to make a dictionary we make use of curley brackets {}, inside you have to give