In this article I would like to say a python string in the standard numeric type in Python, str (), in the hope that it will help you to just touch python.
python Strings (string):
Python strings are a string of characters consisting of numbers, letters, and underscores, which can generally be remembered as follows:
s= "A1A2 An "(n>=0)
(A string is a data type that represents text within a programming language)
The Python string has a total of two order values:
1. The index from left to right begins with the default of 0, and the maximum range is 1 less than the length of the string.
2. Right-to-left index default-1 starts, and the maximum range is the beginning of the string.
If you want to take a string from the string, you can use the [head subscript: Tail subscript] to intercept the desired string, where the head subscript is calculated starting from 0, can be positive or negative, if the tail subscript is empty, then the head and tail are taken. ([head Subscript: tail subscript] The truncated string includes the characters of the following table, but does not contain the trailing subscript character, and takes the character of the first digit of the number written in the trailing subscript. The words may not be convincing. For example:
#!/usr/bin/python#-*-coding:utf-8-*-s = ' 1458592158 ' Print S[2:6]
The result of the above example output is:
5859
When using a colon-delimited string, Python returns a new object that contains the contiguous content identified with the offset, and the beginning of the left contains the bottom bounds.
The result above contains the value B of s[1], and the maximum range taken does not include the trailing subscript, or the value F of s[5].
The plus sign (+) is a string join operator, and an asterisk (*) is a repeating operation . The following example:
#!/usr/bin/python#-*-coding:utf-8-*-str = ' Hello world! ' print str # output full string print str[0] # The first character in the output string print Str[2:5] # The string from the third to the fifth in the output string print str[2:] # Outputs a string starting from the third character print str * 2 # output string two times print str + "TEST" # Lose Out the concatenated string
The results of the above example are as follows:
Hello world! Hllollo world! Hello world! Hello world! Hello world! TEST
These are some examples and applications of Python strings, and I hope to provide some help to friends who have just come into contact with Python.