Python base "day02": String 1

Source: Internet
Author: User

In Python, the string itself has a lot of operations, the character of the string, can not be modified

1, the definition of the string
#定义空字符串
>>> name= '
#定义非空字符串 >>> name= "Luoahong"
#通过下标访问 >>> name[1] ' u '
#不能修改字符串的值, otherwise error >>> name[2] = "3" Traceback (most recent call last): File "<stdin>", line 1, in <modu Le>typeerror: ' str ' object does not support item assignment

Special reminder: If the string is modified, the memory address of the string is changed, so it cannot be modified, but for the list, it can be modified because the memory of the list is constant and can be modified directly above

>>> name= "Ahong luo" >>> name[1:4] ' hon ' >>> name[1:-1] ' Hong Lu ' >>> name[0:3] ' aho ' >>> Name[:3] ' aho ' >>> name[3:] ' ng Luo ' >>> name[0::2] ' Aoglo ' >>> name[::2] ' Aoglo '

  

Python base "day02": String 1

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.