Q. What would be the possible output of the following code fragments?
| Code | Output | Verify | |
|---|---|---|---|
| (a) | a = 4 b = 2 print ("hi" * (a/2)) |
It will give error that “can't multiply sequence by non-int of type 'float'” | Because when we multiply any number to string then that number should be integer otherwise python rise error. |
| (b) | name = "python" print (name.upper()) |
PYTHON | upper() function convert all letters is capital form. |
| (c) | name = "FRED" print (name.lower()) |
fred | lower() function convert all letters is small form. |
| (d) | name = "humberside" print (name [:2]) |
hu | It due to slicing of string. |
| (e) | a = "Middlebury" print (a [4:8]) print (a [8:12]) |
lebu ry |
It due to slicing of string. |
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )