Conversion of Python strings (str) and lists (list)

Source: Internet
Author: User

1.str >>>list

str1 = "12345"
list1 = List (str1)
print list1

str2 = "123 Sjhid dhi"
list2 = Str2.split () #or list2 = str2 . Split ("")
print list2

str3 = "www.google.com"
list3 = Str3.split (".")
Print List3

The output is:
[' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ']
[' 123 ', ' Sjhid ', ' dhi ']
[' www ', ' google ', ' com ']

3.list >>>str

STR4 = "". Join (LIST3)
print str4
STR5 = ".". Join (LIST3)
print str5
STR6 = "". Join (LIST3)
print STR6


The output is:

wwwgooglecom
www.google.com
www google com


Reference Links:

http://blog.csdn.net/cnmcsdn456/article/details/27830671

http://piziyin.blog.51cto.com/2391349/568426


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.