Python learning process-string description

Source: Internet
Author: User

    1. The string in Python is represented by an array, which is similar to the C language (Python is written in C). Because of the character of the string: it is represented by an array of contiguous addresses in memory, so only an exception to the string operation is to open up a piece of memory. So try to use less + connection strings.

    2. If the declaration variable is the same, the address pointing to memory within a certain range is the same. Beyond this range, it is redistributed in memory.

    3. The string comparison = = is the value of the table memory, which is the address of the comparison memory.

    4. String placeholder,%s string,%d number. Format () can also be used. This way you can replace the + connector.

      4.1

      Name = "Sglsjgjj%s%d"

      Name% ("Guo", 100)

      4.2

      Name = "I am {0}, age {1}"

      Name.format ("Guo", 12)

    5. "" "String" "" can represent multiple lines of string.

    6. Name= "Alex" because the string is a character array, name[0]= "a" range: name[0:2]= "Al" Name[0:]= "Alex"

      name[-1]= "x" name[:-1]= Ale

    7. Len (name) Gets the length of the string. Name[-1]=name[len (name)-1]

    8. Name.strip () strips the string two spaces Name.lstrip () to remove the left space. Rstrip () Remove the right space.


This article is from the "Runaway Mustang" blog, please be sure to keep this source http://10846992.blog.51cto.com/10836992/1760322

Python learning process-string description

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.