Q. Given a string as follows:
truehuman = "Loves One and All"
Write the Python expression using string slices (e.g., truehuman [n : m] ) that will produce the given output string. As earlier, verify by typing them in Python Shell.
(You can use only one of the string functions, operators with the slices)
Desired Output | String slice | |
---|---|---|
(a) | 'One an' | |
(b) | 'd All' | |
(c) | ‘LOVES O’ | |
(d) | "AND " | |
(e) | 'and LOVES' | |
(f) | 'ALL IN One' |
Answer :-
Desired Output | String slice | |
---|---|---|
(a) | 'One an' | truehuman[6 : 12] |
(b) | 'd All' | truehuman[12 : ] |
(c) | ‘LOVES O’ | truehuman[ : 7] |
(d) | "AND " | truehuman[10 : 14].upper() |
(e) | 'and LOVES' | truehuman[10 : 14] + truehuman[ : 5].upper() |
(f) | 'ALL IN One' | truehuman[14 : ] + " IN " + truehuman[6 : 9] |
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )