File tree 4 files changed +201
-0
lines changed
4 files changed +201
-0
lines changed Original file line number Diff line number Diff line change
1
+ #Python Numbers variable
2
+ a = 12
3
+
4
+ #print Variable as define format here define is integer
5
+ print (a )
6
+ #output would be
7
+ #12
8
+
9
+ #print Variable as integer convert from define format he a=12 is integer hence will
10
+ print (int (a ))
11
+ #output would be
12
+ #12
13
+
14
+ #print variable as float value from integer as denine
15
+ print (float (a ))
16
+ #output would be
17
+ #12.0
18
+
19
+ #print variable as complex value from integer as denine
20
+ #https://docs.python.org/2/library/functions.html#complex
21
+ print (complex (a ))
22
+ #output would be
23
+ #(12+0j)
24
+
25
+ #for float value change to inter will work like as below
26
+ b = 12.12
27
+ print (int (b ))
28
+ #output would be the integer value as
29
+ #12
30
+
31
+
32
+ # How do we find the variable type from definirion of variable
33
+ a = 12
34
+ print (type (a ))
35
+ #ouput would be
36
+ #
37
+
38
+ a = 12.1
39
+ print (type (a ))
40
+ #ouput would be
41
+ #
42
+
43
+ a = 1 + 2J
44
+ print (type (a ))
45
+ #ouput would be
46
+ #
47
+
48
+ a = True
49
+ print (type (a ))
50
+ #ouput would be
51
+ #
Original file line number Diff line number Diff line change
1
+ # Assume variable a = 10 and variable b = 20
2
+ # Operator Description Example
3
+ # + Addition Adds values on either side of the operator. a + b = 30
4
+ # - Subtraction Subtracts right hand operand from left hand operand. a – b = -10
5
+ # * Multiplication Multiplies values on either side of the operator a * b = 200
6
+ # / Division Divides left hand operand by right hand operand b / a = 2
7
+ # % Modulus Divides left hand operand by right hand operand and returns remainder b % a = 0
8
+ # ** Exponent Performs exponential (power) calculation on operators a**b =10 to the power 20
9
+ # //Floor Division The division of operands where the result is the quotient in which the digits after the decimal point are removed.
10
+
11
+ #Number Format in Hex octa and Binary & Arithmetic Operator Example
12
+
13
+ a = 0b100
14
+ print (a )
15
+ #Output is
16
+ #4
17
+
18
+ a = 0xa
19
+ print (a )
20
+ #Output is
21
+ #10
22
+
23
+ a = 0o100
24
+ print (a )
25
+ #Output is
26
+ #64
27
+
28
+ print ("Arithmetic Operator Example" )
29
+ # Arithmetic Operator Example
30
+ a = 10
31
+ b = 20
32
+
33
+ #Addition Operator
34
+ print (a + b )
35
+ #Output is
36
+ #30
37
+
38
+ #Subscraction Operator
39
+ print (b - a )
40
+ #Output is
41
+ #10
42
+
43
+ #Division Operator
44
+ print (b / a )
45
+ #Output is
46
+ #2.0
47
+
48
+ #Multipication Operator
49
+ print (a * b )
50
+ #Output is
51
+ #200
52
+
53
+ #Power hsm_operation
54
+ c = 2
55
+ d = 2
56
+ print (c ** d )
57
+ #Output is
58
+ #4
59
+
60
+ #Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed.
61
+ e = 9
62
+ f = 2
63
+ print (e // f )
64
+ #Output is
65
+ #4
66
+
67
+ #percentage Operation
68
+ print (e % f )
69
+ #Output is
70
+ #1
71
+
72
+ a = 100
73
+ example = - - - a
74
+ print (example )
75
+
76
+ a = 100
77
+ example = - - a
78
+ print (example )
79
+
80
+ a = 100
81
+ example = + a
82
+ print (example )
83
+
84
+ a = 100
85
+ example = + + a
86
+ print (example )
Original file line number Diff line number Diff line change
1
+ # Operator Description Example
2
+ # == If the values of two operands are equal, then the condition becomes true. (a == b) is not true.
3
+ # != If values of two operands are not equal, then condition becomes true. (a != b) is true.
4
+ # > If the value of left operand is greater than the value of right operand, then condition becomes true. (a > b) is not true.
5
+ # < If the value of left operand is less than the value of right operand, then condition becomes true. (a < b) is true.
6
+ # >= If the value of left operand is greater than or equal to the value of right operand, then condition becomes true. (a >= b) is not true.
7
+ # <= If the value of left operand is less than or equal to the value of right operand, then condition becomes true. (a <= b) is true.a=9
8
+
9
+ a = 9
10
+ b = 2
11
+
12
+ #Comparison Operation retus only boolen value (True/False)
13
+ print (a == b )
14
+ #output would be
15
+ #False
16
+ print (a != b )
17
+ #output would be
18
+ #True
19
+ print (a > b )
20
+ #output would be
21
+ #True
22
+ print (a < b )
23
+ #output would be
24
+ #False
25
+ print (a >= b )
26
+ #output would be
27
+ #True
28
+ print (a <= b )
29
+ #output would be
30
+ #False
31
+
32
+
33
+ print (a and b )
Original file line number Diff line number Diff line change
1
+ #Python Bitwise Operators Example
2
+ a = 50 ,b = 13
3
+ #Operator Description Example
4
+ #& Binary AND Operator copies a bit to the result if it exists in both operands (a & b) (means 0000 0000)
5
+ #| Binary OR It copies a bit if it exists in either operand. (a | b) = 63 (means 0011 1111)
6
+ #^ Binary XOR It copies the bit if it is set in one operand but not both. (a ^ b) = 63 (means 0011 1111)
7
+ #~ Binary Ones Complement It is unary and has the effect of 'flipping' bits. (~a ) = -51 (means 0011 0011 in 2's complement form due to a signed binary number.
8
+ #<< Binary Left Shift The left operands value is moved left by the number of bits specified by the right operand. a << 2 = 200 (means 1100 1000)
9
+ #>> Binary Right Shift The left operands value is moved right by the number of bits specified by the right operand. a >> 2 = 12 (means 0000 1100)
10
+
11
+ a = 50 # 50 = 0011 0010
12
+ b = 13 # 13 = 0000 1101
13
+ output = 0
14
+
15
+ output = a & b ; # 0 = 0000 0000
16
+ print ("Operator & Output Value is " , output )
17
+
18
+ output = a | b ; # 63 = 0011 1111
19
+ print ("Operator | Output Value is " , output )
20
+
21
+ output = a ^ b ; # 63 = 0011 1111
22
+ print ("Operator ^ Output Value is " , output )
23
+
24
+ output = ~ a ; # -51 = 0011 0011
25
+ print ("Operator ~ Output Value is " , output )
26
+
27
+ output = a << 2 ; # 200 = 1100 1000
28
+ print ("Operator << Output Value is " , output )
29
+
30
+ output = a >> 2 ; # 12 = 0000 1100
31
+ print ( "Operator >> Output Value is " , output )
You can’t perform that action at this time.
0 commit comments