The Python String type can bring us great benefits in practical applications. In the next article, we will introduce the Python String-type application methods in detail here. I hope you can fully master this application.
Python String application code example:
- >>> 'hello world'
- 'hello world'
- >>> "hello world"
- 'hello world'
- >>> "doesn't"
- "doesn't"
- >>> 'hello "tom"'
- 'hello "tom"'
- >>> "hello,\"tom\""
- 'hello,"tom"'
- >>> hello="hello,\
- i miss you."
- >>> print(hello)
- hello,i miss you.
- >>> print(r"hello\n world")
- hello\n world
- >>> word='hello'+'A'
- >>> print(word)
- helloA
- >>> word[0:5]+'B'
- 'helloB'
- >>> word[-1]
- 'A'
- >>> len(word)
Note:
- Main steps for Python to call. net framework
- Python coding experience in creating Silverlight controls
- Python parsing XML correct application code example
- Analysis of Python image Optimization Techniques
- Python file path
Single quotation marks 'and double quotation marks "have the same effect and are used to represent strings. However, single quotation marks' can contain double quotation marks" ", double quotation marks '', however, if double quotation marks "" are used in double quotation marks "" or single quotation marks ''are used in single quotation marks, escape characters must be used, such as \ 'or \".
The end of the line \ indicates the string line break.
The r before the string indicates a pure string, and The Escape Character in the string is invalid.
+ Indicates the link of a string.
[] Can be used to index characters in a string, but cannot be used to modify characters in a string.
Len () is used to obtain the length of a string.
The above is an introduction to the Python String type.