Chapter 8
Chapter 8
Chapter 8
Output:
Data type of num_int: <class 'int'>
Data type of num_str before Type Casting: <class 'str'>
Data type of num_str after Type Casting: <class 'int'>
Sum of num_int and num_str: 579
Data type of the sum: <class 'int'>
eval() function
the eval function evaluates the “String” like a python
expression and returns the result as an integer.
provide the input as a string.
Syntax:
eval(expression, [globals[, locals]])
Example: eval('2+3‟)
O/P: 5
# Output: True
print(1 in y)
# Output: False
print('a' in y)
OUTPUT:
enter a no.=10
10 is greater than zero
a=int(input("enter a no.="))
if a > 0:
print(a," is posti")
else:
print(a," is nega")
OUTPUT:
enter a no.=-2
-2 a= is nega
The elif is short for else if. It allows us to check for multiple expressions.
If the condition for if is False, it checks the condition of the next elif block
and so on.
If all the conditions are False, the body of else is executed.
Only one block among the several if...elif...else blocks is executed
according to the condition.
The if block can have only one else block. But it can have multiple elif
blocks.
Faculty: Komal Waykole
80
if...elif...else Statement flowchart