Sunday, April 21, 2019
Sunday, April 7, 2019
Friday, April 5, 2019
Python Day -> 1
In [1]:
#Python Basic
In [2]:
print('I am not bad')
I am not bad
In [3]:
print("I am not bad")
I am not bad
In [4]:
4 * 5
Out[4]:
20
In [5]:
2 - 1
Out[5]:
1
In [6]:
2 * 4
Out[6]:
8
In [7]:
6 / 2
Out[7]:
3.0
In [8]:
int(6 / 2)
Out[8]:
3
In [14]:
# Variable
In [15]:
'''
# Python reserved keyword. These below list you can not assign varible name.
False None True
and exec not
as finally or
assert for pass
break from print
class global raise
continue if return
def import try
del in while
elif is with
else lambda yield
except
'''
Out[15]:
'\n# Python reserved keyword. These below list you can not assign varible name.\nFalse\tNone\tTrue\nand\texec\tnot\nas\tfinally\tor\nassert\tfor\tpass\nbreak\tfrom\tprint\nclass\tglobal\traise\ncontinue\tif\treturn\ndef\timport\ttry\ndel\tin\twhile\nelif\tis\twith\nelse\tlambda\tyield\nexcept\n'
In [16]:
a = 2
In [17]:
b = 3
In [18]:
a + b
Out[18]:
5
In [19]:
c = a + b
In [20]:
print (c)
5
In [31]:
#Data type
In [32]:
type(a)
Out[32]:
int
In [33]:
d = 3.14
In [34]:
type(d)
Out[34]:
float
In [35]:
e = 'power'
In [36]:
type(e)
Out[36]:
str
In [37]:
f = "BH"
In [38]:
type(f)
Out[38]:
str
In [39]:
g = True
In [40]:
type(g)
Out[40]:
bool
In [41]:
#Other data type
'''
long, complex, unicode, list, tuple, set, dict
'''
Out[41]:
'\n long, complex, unicode, list, tuple, set, dict \n'
In [42]:
long = 1
In [43]:
long
Out[43]:
1
In [44]:
#Data Input
In [45]:
a = input()
15
In [47]:
b = input()
10
In [48]:
a + b
Out[48]:
'1510'
In [49]:
#Type casting
'''
int() Integer cast
float() float cast
str() String cast
tuple() Tuple cast
list() List cast
set() Set cast
dict() Dictonary cast
'''
Out[49]:
'\nint()\tInteger cast\nfloat()\tfloat cast\nstr()\tString cast\ntuple()\tTuple cast\nlist()\tList cast\nset()\t Set cast\ndict()\t Dictonary cast\n'
In [50]:
a = 5
In [51]:
type(a)
Out[51]:
int
In [52]:
a = str(a)
In [53]:
type(a)
Out[53]:
str
In [66]:
#Input
In [67]:
a = input()
In [68]:
a = int(a)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-68-8941b20ea7e0> in <module> ----> 1 a = int(a) ValueError: invalid literal for int() with base 10: ''
In [69]:
b = 10
In [70]:
b = int(b)
In [58]:
a + b
Out[58]:
25
In [60]:
a = int(input())
15
In [61]:
b = int(input())
10
In [62]:
a,b = input().split()
15 10
In [63]:
a
Out[63]:
'15'
In [64]:
b
Out[64]:
'10'
In [65]:
type(b)
Out[65]:
str
In [71]:
a,b = map(int, input().split())
15 10
In [72]:
a + b
Out[72]:
25
In [105]:
# Arithmetic opertaor 7 type
In [106]:
'''
+ add op
- subtraction op
* multi op
/ divison op
% modulas op
** exponent op
// floor divison op
'''
Out[106]:
'\n+ add op\n- subtraction op\n* multi op\n/ divison op\n% modulas op\n** exponent op\n// floor divison op\n'
In [107]:
2 + 2
Out[107]:
4
In [108]:
3 - 1
Out[108]:
2
In [109]:
2 * 2
Out[109]:
4
In [110]:
4 / 2
Out[110]:
2.0
In [111]:
4 // 2
Out[111]:
2
In [112]:
10 / 3
Out[112]:
3.3333333333333335
In [113]:
10 % 3
Out[113]:
1
In [114]:
3 ** 2
Out[114]:
9
In [115]:
math.pow(3, 2)
Out[115]:
9.0
In [116]:
import math
In [117]:
math.pow(3,2)
Out[117]:
9.0
In [119]:
# Comparison Operator 6 type
In [120]:
'''
== equal equal
!= not equal
> Greater than
< less than
>= Greater than or equal operator
<=less than or equal operator
'''
Out[120]:
'\n==\tequal equal \n!=\tnot equal\n>\tGreater than\n<\tless than\n>=\tGreater than or equal operator\n<=less than or equal operator\n'
In [121]:
2 == 2
Out[121]:
True
In [122]:
2 != 2
Out[122]:
False
In [123]:
5 < 3
Out[123]:
False
In [124]:
5 > 3
Out[124]:
True
In [125]:
5 <= 5
Out[125]:
True
In [126]:
5 >= 3
Out[126]:
True
In [127]:
5 > 5
Out[127]:
False
In [128]:
# Assignment Operator 5 type
In [129]:
'''
=
+=
-=
*=
/=
'''
Out[129]:
'\n=\n+=\n-=\n*=\n/=\n'
In [134]:
a = 5
In [135]:
a = a + 2
In [136]:
a
Out[136]:
7
In [137]:
a += 2
In [138]:
a
Out[138]:
9
In [139]:
# Logical Operator 3 type
In [140]:
'''
and -----> &&
or -------> ||
not ------> !
'''
Out[140]:
'\nand -----> && \nor -------> ||\nnot ------> !\n'
In [141]:
2 == 2 && 3==3
File "<ipython-input-141-744ec8abfd5d>", line 1 2 == 2 && 3==3 ^ SyntaxError: invalid syntax
In [142]:
2 == 2 and 3 == 3
Out[142]:
True
In [143]:
2 == 2 or 3 == 4
Out[143]:
True
In [144]:
3 == 4 or 2 == 2
Out[144]:
True
In [145]:
'''
True and True = True
True and False = False
False and True = False
False and False = False
---------------------------
True or True = True
True and False = True
False and true = True
False and False = False
'''
Out[145]:
'\nTrue and True = True\nTrue and False = False\nFalse and True = False \nFalse and False = False\n---------------------------\nTrue or True = True\nTrue and False = True \nFalse and true = True \nFalse and False = False\n'
In [146]:
2 == 5
Out[146]:
False
In [147]:
not 2 == 5
Out[147]:
True
In [148]:
'''
not (False) = True
not (True) = Flase
'''
Out[148]:
'\nnot (False) = True \nnot (True) = Flase\n'
In [149]:
# Membership Operrator 2 type
In [150]:
'''
in
not in
'''
Out[150]:
'\nin\nnot in\n'
In [151]:
a = 'Bangladesh'
In [152]:
b = 'desh'
In [153]:
a in b
Out[153]:
False
In [154]:
b in a
Out[154]:
True
In [155]:
b = 'desh'
In [156]:
c = 'desh'
In [157]:
b in c
Out[157]:
True
In [158]:
c in b
Out[158]:
True
In [159]:
# Identity Oprator 2 type
In [161]:
'''
is
is not
'''
Out[161]:
'\nis \nis not\n'
In [162]:
a = 'Bangladesh'
In [163]:
b = 12
In [164]:
a is b
Out[164]:
False
In [165]:
a is not b
Out[165]:
True
In [166]:
a = 1
In [167]:
b = 1
In [168]:
a is b
Out[168]:
True
In [169]:
a is not b
Out[169]:
False
In [170]:
a = 257
In [171]:
b = 257
In [172]:
b is a
Out[172]:
False
In [173]:
a is b
Out[173]:
False
In [174]:
a = 256
In [175]:
b = 256
In [176]:
a is b
Out[176]:
True
In [177]:
b is a
Out[177]:
True
In [178]:
# Python resever 256 intger in cache memory data range between [-5, 256]. is operator range working [-5,256]
In [182]:
# Comment in Python
'''
# ##########
'''
Out[182]:
'\n# ##########\n'
In [183]:
a = 15 # a is a dividend. This comment name is inline commment
In [184]:
# a is an int variable
... # This is another comment.
...
In [185]:
# a is an int variable
... # This is another comment.
#This comment name is 'Block comment'
...
In [186]:
# a is an int variable
... # This is another comment.
This comment name is 'Block comment'
...
File "<ipython-input-186-6ec8084bbcf3>", line 3 This comment name is 'Block comment' ^ SyntaxError: invalid syntax
In [187]:
"""
This comment name is doc string comment.Also this one is String.
"""
Out[187]:
'\nThis comment name is doc string comment.Also this one is String.\n'
In [188]:
'''
another way doc comment
'''
Out[188]:
'\nanother way doc comment \n'
In [ ]:
Subscribe to:
Posts (Atom)