+ 1

List Operations on String?

I should have asked this question a long time ago, but for some reason I cannot perform list operations on a string. Lets say I want to reverse a string. Why cant I enter string.reverse() EVEN WHEN i do list(string). Is there a way I can perform list operations on strings without errors?

19th Nov 2017, 9:12 PM
privrax.
privrax. - avatar
2 Réponses
0
hi , please test it for reversing string : string = "abolfazl" print(string) print(string[::-1])
20th Nov 2017, 8:30 PM
abolfazl meyarian
abolfazl meyarian - avatar
0
#hope it help data = [ [23, 11, 5, 14], [8, 32, 20, 5] ] color = input() total=23+11+5+14+8+32+20+5 if color == "brown": print(int((data[0][0]+data[1][0])*100/total)) elif color == "blue": print(int((data[0][1]+data[1][1])*100/total)) elif color == "green": print(int((data[0][2]+data[1][2])*100/total)) else: print(int((data[0][3]+data[1][3])*100/total))
6th Jan 2023, 4:57 PM
Alin Ursulescu