Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python3
python
string
communitycreator

What is the partition() method in Python?

Dario Vincenzo Tarantini

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The partition() method in Python cuts a string into three parts with a delimiter.

Syntax

 `string.partition(delimiter)` 

This method will only search the first occurrence of the delimiter.

Return value

This method will return a tuple with three values: the string before the delimiter, the delimiter itself, and the string after it.

If it doesn’t find the delimiter, it will return a tuple with only the string as the first element.

Example

print("educative is awesome!".partition("is "))
print("educative is awesome!".partition("hello"))

RELATED TAGS

python3
python
string
communitycreator

CONTRIBUTOR

Dario Vincenzo Tarantini

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring