python partition
时间: 2023-09-05 22:13:41 浏览: 91
python中partition的使用
5星 · 资源好评率100%
Python's partition() method is used to split a string into three parts based on a separator. It returns a tuple containing three elements: the substring before the separator, the separator itself, and the substring after the separator.
The syntax for partition() method is:
string.partition(separator)
Here is an example of using partition() method:
```
sentence = "I love programming in Python"
result = sentence.partition("programming")
print(result)
```
Output:
```
('I love ', 'programming', ' in Python')
```
In the above example, the partition() method has split the string "I love programming in Python" into three parts based on the separator "programming". The first part is "I love ", the second part is "programming", and the third part is " in Python".
阅读全文