The syntax of partition() is:
string.partition(separator)
The partition() method takes a string parameter separator that separates the string at the first occurrence of it.
The partition method returns a 3-tuple containing:
string = "Python is fun" # 'is' separator is found print(string.partition('is ')) # 'not' separator is not found print(string.partition('not ')) string = "Python is fun, isn't it" # splits at first occurence of 'is' print(string.partition('is'))
When you run the program, the output will be:
('Python ', 'is ', 'fun') ('Python is fun', '', '') ('Python ', 'is', " fun, isn't it")