String inversion in Golang, Python.

Source: Internet
Author: User
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))
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.