Datatypes&Operators
Datatypes&Operators
Welcome to Innomatics
Welcome to innomatics
Greetings of the day !!
In [3]: a = 23
b = 56
In [4]: print(a)
23
In [5]: print(b)
56
The value of a is : 23
Keywords
In [7]: import keyword
print(keyword.kwlist)
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not',
'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
In [8]: print(len(keyword.kwlist))
35
Identifiers
Identifier is a name of a variable,class, function, module or an object.
In [9]: a = 23
In [10]: area = 78
Variables
In [11]: a = 20
In [12]: b = 34
In [13]: a
Out[13]: 20
In [14]: b
Out[14]: 34
In [15]: c = a+b
In [16]: c
Out[16]: 54
In [17]: print(a)
20
In [18]: print(a,b)
20 34
In [19]: print(a,b,c)
20 34 54
In [21]: a
Out[21]: 10
In [22]: b
Out[22]: 20
In [23]: c
Out[23]: 30
In [24]: a,b,c
In [25]: print(a,b,c)
10 20 30
In [26]: a = 20
In [29]: a = b = c = 45
In [30]: a,b,c
In [32]: Width = 20
Height = 25
Rectangle_area = Width * Height
print('Area of Rectanglle is : ',Rectangle_area)
30
Enter A value: 45
Enter B value: 34
The addition Result is: 79
Input ( ) Method
In [38]: print(help(input))
Raises
------
StdinNotImplementedError if active frontend doesn't support stdin.
None
Input( ) takes inputs dynamically from the user ( keyboard) By default it takes data as a string
In [41]: data = input('Enter your Data: ')
In [42]: data
Out[42]: '45'
In [43]: D = input()
In [44]: D
Data Types
Numeric Data Types
1. Integer
2. Float
3. Complex
In [45]: #Integers
a = 23
b = 4567
c = -789
Type ( )
In [51]: type(a)
Out[51]: int
In [52]: type(b)
Out[52]: int
In [53]: # float
a = 34.78
b = 45.900234545
c = -67.432
In [55]: #complex
a = 3+7j
b = -5-8j
c = -3j
print('The data type of a variable a is : ',type(a))
print('The data type of a variable b is : ',type(b))
print('The data type of a variable c is : ',type(c))
In [57]: a = 10
print(type(a))
<class 'int'>
<class 'float'>
In [62]: c = str(a)
In [63]: print(type(c))
<class 'str'>
In [59]: a = 45.89
print(type(a))
<class 'float'>
<class 'int'>
In [65]: b
Out[65]: 45
Out[66]: 45.89
In [67]: c = str(a)
print(type(c))
print(c)
<class 'str'>
45.89
In [68]: c
Out[68]: '45.89'
This is possible if at all if the string literal is equal to any numerical value of base10
In [69]: a = '167'
In [70]: type(a)
Out[70]: str
In [71]: b = int(a)
print(b,type(b))
In [72]: x = 'satya'
type(x)
Out[72]: str
In [74]: b = float(a)
print(b,type(b))
String
String is sequence of characters which are enclosed with either single quotes ' ' or double quotes " "
In [76]: type(a)
Out[76]: str
In [78]: type(b)
Out[78]: str
In [81]: a
Out[81]: 'Hello all , Greetings of the day!!!!\nWelcome to Innomatics Research labs\nHappy Learning!! Thank you'
Operators in Python
1. Arithmetic Operators
2. Assignment Operators
3. Comparision Operators/Relationship operators
4. Logical Operators
5. Membership Operator
6. Identity Operators
7. Bitwise Operators
Arithmetic Operators
1. Afddition --> +
2. Subtraction -->-
3. Multiplication --> *
4. Division --> /
5. modulus --> %
6. Floor Division --> //
7. Exponentation --> **
In [82]: #Addition
In [83]: a = 20
b = 10
In [84]: a+b
Out[84]: 30
In [85]: #subtraction
a-b
Out[85]: 10
In [86]: #multiplication
a*b
Out[86]: 200
In [87]: #division
a/b
Out[87]: 2.0
Out[88]: 0
In [89]: a = 25
b = 8
a%b
Out[89]: 1
Out[90]: 3
In [91]: a/b
Out[91]: 3.3333333333333335
In [94]: np.floor(a/b)
Out[94]: 3.0
In [95]: np.ceil(a/b)
Out[95]: 4.0
In [96]: np.abs(a/b)
Out[96]: 3.3333333333333335
In [97]: #exponentation
a = 2
b = 3
a**b
Out[97]: 8
In [98]: b**a
Out[98]: 9
Assignment Operators
Assignment operator ( = ) is used to assign values to the variable
In [99]: a = 20
In [101… a
Out[101]: 30
Out[102]: 20
In [104… a/=2
a
Out[104]: 5.0
In [106… a//=2
a
Out[106]: 1.0
Comparision Operators
Comparision Operators are used to compare values and variables
Out[107]: True
In [108… a = 34
b = 25
a >b
Out[108]: True
In [109… b>a
Out[109]: False
Out[110]: True
In [111… 5 < 3
Out[111]: False
In [112… a,b
In [113… b < a
Out[113]: True
In [115… a = 23
b = 23
In [116… a >= b
Out[116]: True
In [117… a = 56
b = 23
a >= b
Out[117]: True
Out[118]: True
In [120… a = 53
b = 26
a <= b
Out[120]: False
In [122… a = 23
b = 56
a == b
Out[122]: False
In [123… a = 10
b = 10
a == b
Out[123]: True
a = 45
b = 56
a != b
Out[124]: True
In [125… a = 10
b = 10
a != b
Out[125]: False
In [ ]: