This article mainly introduces you to the knowledge about strings in Python. A friend who wants to touch a Python language is probably not too familiar with the string in Python,
python stringSTR is one of the most common basic data types in Python programming, and cannot be encoded by bypassing strings when using the Python language. I'm going to take you down here and get a look.
the correct Python stringKnowledge and how to perform string operations such as
interception of Python stringsand update
Python string:
The string is the most commonly used data type in Python. We can use quotation marks (' or ') to create a string.
Creating a string is simple, as long as you assign a value to the variable. For example:
var1 = ' Hello world! ' VAR2 = "Blue Sky"
The above example is simple, let me explain the values in the Python access string :
Python does not support single character types, and single-character is used as a string in Python.
Python accesses substrings, which can be used to intercept python strings using square brackets.
Examples are as follows:
#!/usr/bin/python var1 = ' Hello world! ' VAR2 = "Python runoob" print "var1[0]:", Var1[0]print "Var2[1:5]:", Var2[1:5]
The output value of the above example is:
Var1[0]: hvar2[1:5]: ytho
This belief should be better understood, the first is to intercept "Hello world!" The first string "H", the second one is to intercept the first to the fourth string, which is "Ytho". To intercept a string believe it is quite a simple thing to believe that everyone should have understood.
Now let's look at the python string update :
As the name implies, a string update is where you can modify an existing string and assign a value to another variable, such as the following example:
#!/usr/bin/python#-*-coding:utf-8-*-var1 = ' Hello world! ' print ' Update string:-", var1[:6] + ' runoob! '
This is quite simple and the output is as follows:
Update string:- Hello runoob!
This article describes the strings in Python and the interception of strings, as well as the updating of strings, and adds examples to help you understand and learn. Because of the number of knowledge points of the string, there will be an article on the string knowledge points and examples of analysis to help you to learn. Hopefully this article will give you a little help in learning about Python.
For more information, please visit the PHP Chinese Web Python tutorial section.