In [1]:
#Python Basic
In [2]:
print('I am not bad')
In [3]:
print("I am not bad")
In [4]:
4 * 5
Out[4]:
In [5]:
2 - 1
Out[5]:
In [6]:
2 * 4
Out[6]:
In [7]:
6 / 2
Out[7]:
In [8]:
int(6 / 2)
Out[8]:
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]:
In [16]:
a = 2
In [17]:
b = 3
In [18]:
a + b
Out[18]:
In [19]:
c = a + b
In [20]:
print (c)
In [31]:
#Data type
In [32]:
type(a)
Out[32]:
In [33]:
d = 3.14
In [34]:
type(d)
Out[34]:
In [35]:
e = 'power'
In [36]:
type(e)
Out[36]:
In [37]:
f = "BH"
In [38]:
type(f)
Out[38]:
In [39]:
g = True
In [40]:
type(g)
Out[40]:
In [41]:
#Other data type
'''
long, complex, unicode, list, tuple, set, dict
'''
Out[41]:
In [42]:
long = 1
In [43]:
long
Out[43]:
In [44]:
#Data Input
In [45]:
a = input()
In [47]:
b = input()
In [48]:
a + b
Out[48]:
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]:
In [50]:
a = 5
In [51]:
type(a)
Out[51]:
In [52]:
a = str(a)
In [53]:
type(a)
Out[53]:
In [66]:
#Input
In [67]:
a = input()
In [68]:
a = int(a)
In [69]:
b = 10
In [70]:
b = int(b)
In [58]:
a + b
Out[58]:
In [60]:
a = int(input())
In [61]:
b = int(input())
In [62]:
a,b = input().split()
In [63]:
a
Out[63]:
In [64]:
b
Out[64]:
In [65]:
type(b)
Out[65]:
In [71]:
a,b = map(int, input().split())
In [72]:
a + b
Out[72]:
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]:
In [107]:
2 + 2
Out[107]:
In [108]:
3 - 1
Out[108]:
In [109]:
2 * 2
Out[109]:
In [110]:
4 / 2
Out[110]:
In [111]:
4 // 2
Out[111]:
In [112]:
10 / 3
Out[112]:
In [113]:
10 % 3
Out[113]:
In [114]:
3 ** 2
Out[114]:
In [115]:
math.pow(3, 2)
Out[115]:
In [116]:
import math
In [117]:
math.pow(3,2)
Out[117]:
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]:
In [121]:
2 == 2
Out[121]:
In [122]:
2 != 2
Out[122]:
In [123]:
5 < 3
Out[123]:
In [124]:
5 > 3
Out[124]:
In [125]:
5 <= 5
Out[125]:
In [126]:
5 >= 3
Out[126]:
In [127]:
5 > 5
Out[127]:
In [128]:
# Assignment Operator 5 type
In [129]:
'''
=
+=
-=
*=
/=
'''
Out[129]:
In [134]:
a = 5
In [135]:
a = a + 2
In [136]:
a
Out[136]:
In [137]:
a += 2
In [138]:
a
Out[138]:
In [139]:
# Logical Operator 3 type
In [140]:
'''
and -----> &&
or -------> ||
not ------> !
'''
Out[140]:
In [141]:
2 == 2 && 3==3
In [142]:
2 == 2 and 3 == 3
Out[142]:
In [143]:
2 == 2 or 3 == 4
Out[143]:
In [144]:
3 == 4 or 2 == 2
Out[144]:
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]:
In [146]:
2 == 5
Out[146]:
In [147]:
not 2 == 5
Out[147]:
In [148]:
'''
not (False) = True
not (True) = Flase
'''
Out[148]:
In [149]:
# Membership Operrator 2 type
In [150]:
'''
in
not in
'''
Out[150]:
In [151]:
a = 'Bangladesh'
In [152]:
b = 'desh'
In [153]:
a in b
Out[153]:
In [154]:
b in a
Out[154]:
In [155]:
b = 'desh'
In [156]:
c = 'desh'
In [157]:
b in c
Out[157]:
In [158]:
c in b
Out[158]:
In [159]:
# Identity Oprator 2 type
In [161]:
'''
is
is not
'''
Out[161]:
In [162]:
a = 'Bangladesh'
In [163]:
b = 12
In [164]:
a is b
Out[164]:
In [165]:
a is not b
Out[165]:
In [166]:
a = 1
In [167]:
b = 1
In [168]:
a is b
Out[168]:
In [169]:
a is not b
Out[169]:
In [170]:
a = 257
In [171]:
b = 257
In [172]:
b is a
Out[172]:
In [173]:
a is b
Out[173]:
In [174]:
a = 256
In [175]:
b = 256
In [176]:
a is b
Out[176]:
In [177]:
b is a
Out[177]:
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]:
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'
...
In [187]:
"""
This comment name is doc string comment.Also this one is String.
"""
Out[187]:
In [188]:
'''
another way doc comment
'''
Out[188]:
In [ ]:
No comments:
Post a Comment