Example HTML page

Python Exercise 5

The following examples are an exercise on type conversions. your task is execute every statement and write the reason for getting the corresponding output/error.

bool()

1. bool(True)
2. bool(False)
3. bool(True, False)
4. bool(True * False)
5. bool(10)
6. bool(0)
7. bool(1)
8. bool(-10)
9. bool(”)
10. bool(“Sudhakar”)
11. bool(1+2j)
12. bool(0+0j)
13. bool(“0+5j”)

int()

1. int(True)
2. int(False)
3. int(True+True)
4. int(True/False)
5. int(False/False)
6. int(“1000”)
7. int(“Sudhakar”)
8. int(4+5j)
9. int(“10.6”)
10. int(bool(0.5))
11. int(0x1234)
12. int(0o1234)
13. int(0B1010)

float()

1. float(True)
2. float(False)
3. float(100/10)
4. float(100//10)
5. float(“100/100”)
6. float(“Sudhakar”)
7. float(“0x1234”)
8. float(0x1234)
9. float(“100”)
10. float(5+6j)
11. float(“5+6j”)
12. float(” “)
13. float(bool(True/false))

complex()

1. complex(1)
2. complex(0)
3. complex(1,2)
4. complex(1.2,3.3)
5. complex(0,1.2)
6. complex(“10″,”12”)
7. complex(“ten”,”Twelve”)
8. complex(True)
9. complex(False)
10. complex(True,False)
11. complex(False,True)
12. complex(“10.2″,”1.3”)
13. complex(0x1234)

Example HTML page

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest