This is a created article in which the information may have evolved or changed.
In go, it needs to be handled with Rune because it involves Chinese or some characters ASCII encoding greater than 255.
Func Main () { fmt. Println (Reverse ("Golang python"))}func reverse (src String) string { DST: = []rune (src) len: = Len (DST) var result []rune result = Make ([]rune, 0) for i: = len-1; I >= 0; i--{ result = Append (result, dst[i]) } return string (Result)}
In Python, there are several methods, one is the operation of the list, one is the system's own function, and the previous traversal method is used.
#方法1--------------------------------------s = ' Golang python ' print (s[::-1]) # Method 2--------------------------------------s = ' Golang python ' L = list (s) l.reverse () print ('. Join (L)) # Method 3--------------------------------------s = ' Golang python ' str=[]k=0for i in S: Str.append (S[len (s) -1-k]) k=k+1print (". Join (str)) #方法4--------------------------------------s = ' Golang python ' str=[]for i in S: Str.insert (0,i) print (". Join (STR))