Home  >  Article  >  Backend Development  >  Detailed introduction to python strings

Detailed introduction to python strings

高洛峰
高洛峰Original
2017-03-22 11:27:081460browse

Python has five major data types, which are: Use the type built-in function to view the data type

1: str (string) 2: int (integer) 3: float (floating point number)

3: list (list) 4: dict (dictionary) 5: set (set)

str (string) is an immutable type: the value corresponding to each variable is actually only in memory Associating data with variable names, when the value of B is modified, it is actually just opening up a new space in the memory, pointing B to the newly opened space, and does not directly change the data in the memory space that B originally pointed to: as shown in the figure

Detailed introduction to python strings

Python has many built-in methods for each data type. Flexible use of these methods can greatly reduce the amount of our code. Below I list the methods of strings for everyone. Some common methods:

str.replace()                                                                                                                                                                                                                                       // String replacement

Detailed introduction to python strings

##str.strip('/')                           

Detailed introduction to python strings

str.split()                                                                                                                                                                                                                                                                               ​ 

Detailed introduction to python strings##str.startswith()                                                                                                                                                                                                                                                               ​Change the string to lowercase

Detailed introduction to python strings

##str.upper()                                           ’’’’’  Detailed introduction to python strings


#'Specify splicing symbol'.join(str) //String splicing Detailed introduction to python strings

String slice: Detailed introduction to python strings

## characters String splicing:

Detailed introduction to python strings

There are many built-in methods for strings, but these are the most commonly used ones. I hope it will be helpful to all my friends.

The above is the detailed content of Detailed introduction to python strings. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn