Python Learning Note 2: Strings

Source: Internet
Author: User

Python Learning Note 2: Strings

Summary : strings are immutable variables and cannot be modified by subscript

The method of the string does not change the original value of the string, but it is reborn into a string

One or 3 ways of writing--single quotation marks, double quotes, three quotation marks

  

Second, subscript and slicing

Subscript: The position of each character in the string, also called the index. Strname[n], which represents the value of the character that strname the string's subscript to N.

      

   Slice : The value of a subscript interval to take a string. STRNAME[N:M], indicating strname the string, subscript N to M in this interval value, note n:m value, Gubai disregard.

      

Three, String traversal

In and not in

  

For loop traversal string

Iv. Methods of strings

1, Upper (), lower (), Isupper (), Islower ()--case conversion and case sensitivity

    

   2, IsX

Isalnum () Determines whether a string contains only numbers and letters

Isalpha () to determine if the string contains only English letters

IsDigit () Determines whether a string contains only numbers

      

    3. Find () Method--Find the index of the first occurrence of the string

      

   4. Format () Method--string formatting

      

   5. Join () method --Connect an iterative object through a string

      1) Connect an iterative object-string, such as *, through a string

         

2) Connect an iterative object-the tuple/list element through a string, such as *

         

3) through a string, such as *, to connect an iterative object-the element in the dictionary (because traversing the dictionary is actually the key value of traversing the dictionary)

  6, Strip (), Lstrip (), Rstrip () method--go to the left and right side of the space to enter, remove the left side of the space carriage return, remove the blank space.

      

   7.Split () method --cut the string with an identity as standard, return a list

      

    8. Replace () method--replacement

      

   9, string.ascii--print ASCII code letter

Python Learning Note 2: Strings

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.