Page 437 - AI Ver 3.0 class 10_Flipbook
P. 437
For example:
• 2 + 5 * (15 - 10) // 2 will be evaluated as follows:
2+5*(5)//2 since * and // have same precedence, it will be evaluated from left to right.
2+12
14
• 25%3%2
To evaluate the above expression it works like (25%3)%2.
1%2= 1
• 2**2**3
This expression is evaluated from right to left. Here it will be equivalent to 2**(2**3). The result is 256.
Task 21 st Century #Critical Thinking
Skills
Evaluate the following expressions:
10+20/5-3*2
(23+5)*7/5+(3*2)
45//2+(6+5)*2
16%3+56-4+(35//5)
12+56-16*4%3*3
Type Conversion
Type conversion is the process of converting the value of one data type into another data type to match the
operation required to be performed by the code. Python supports two different types of type conversion.
Implicit Type Conversion
When the process of converting the value of one data type into another data type is done automatically without
involving any action from the programmer is called Implicit Type conversion. Python always converts smaller
data types to larger data types to avoid the loss of data.
[1]: a = 5
print("The datatype of a is :",type(a) )
b = 6.5
print("The datatype of b is :",type(b))
a=a+b
print("Value of a after addition is :",a)
print("Datatype of a after addition is :", type(a))
The datatype of a is : <class 'int'>
The datatype of b is : <class 'float'>
Value of a after addition is : 11.5
Datatype of a after addition is : <class 'float'>
Advance Python (Practical) 435

