split
uses to tokenize the stringletters = 'A, B, C, D'
letters.split(', ')
letters.split(', ', 2)
rsplit
performs the same task as split
but processes the maximum number of splits from the end of the string toward the beginningjoin
concatenates the strings in its argument, which must be an iterable containing only string valuesjoin
letters_list = ['A', 'B', 'C', 'D']
','.join(letters_list)
','.join([str(i) for i in range(10)])
partition
and rpartition
¶String method partition
splits a string into a tuple of three strings based on the method’s separator argument
'Amanda: 89, 97, 92'.partition(': ')
rpartition
url = 'http://www.deitel.com/books/PyCDS/table_of_contents.html'
rest_of_url, separator, document = url.rpartition('/')
document
rest_of_url
splitlines
¶splitlines
returns a list of new strings representing lines of text split at each newline character in the original stringlines = """This is line 1
This is line2
This is line3"""
lines
lines.splitlines()
True
to splitlines
keeps the newlineslines.splitlines(True)
©1992–2020 by Pearson Education, Inc. All Rights Reserved. This content is based on Chapter 5 of the book Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and the Cloud.
DISCLAIMER: The authors and publisher of this book have used their best efforts in preparing the book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The authors and publisher make no warranty of any kind, expressed or implied, with regard to these programs or to the documentation contained in these books. The authors and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs.