string= ' 1 2 3 4'
for ch in string[: : -1]:
print(ch , end = " , " )
a) 4,1,2,,3
b)4,3,2,,1
c)4,3,2,1
d)4,1,2,3
1
Answers
Answered by
1
Answer:
hello,
Explanation:
- string= ' 1 2 3 4' # here u have assigned value to the string
- for ch in string[: : -1]: # this statement is using for loop to read each character in the given string using indexing method
- print(ch , end = " , " )#this statement is used to print each letter in the format as mentioned in the loop
" if the statement would have been print(ch) then the output would have been in different lines but since it is print(ch,end=",") output will be in the same line with comma in between each of them "
now giving appropriate index:
character -forward index -reverse index
1 - 0 - (-4)
2 - 1 - (-3)
3 - 2 - (-2)
4 - 3 - (-1)
hence the output is:
4 , 3 , 2 , 1 ,
hope it helps you
please mark brainliest
@ItzSnowySecret07
Similar questions