Python String split() MethodPython split() method splits the string into a comma separated list. It separates string based on the separator delimiter. This method takes two parameters and both are optional. It is described below. SignatureParameterssep: A string parameter acts as a seperator. maxsplit: Number of times split perfome. ReturnIt returns a comma separated list. Let's see some examples of split() method to understand it's functionality. Python String split() Method Example 1This is a simple example to understand the usage of split() method. No parameter is given, by default whitespaces work as separator. See the example below. Output: Java is a programming language ['Java', 'is', 'a', 'programming', 'language'] Python String split() Method Example 2Let's pass a parameter separator to the method, now it will separate the string based on the separator. See the example below. Output: ['', ' is a programming language'] Python String rsplit() Method Example 3The string is splited each time when a is occurred. See the example below. Output: Java is a programming language ['J', 'v', ' is ', ' progr', 'mming l', 'ngu', 'ge'] Python String split() Method Example 4Along with separator, we can also pass maxsplit value. The maxsplit is used to set the number of times to split. Output: ['J', 'va is a programming language'] ['J', 'v', ' is ', ' programming language']
Next TopicPython Strings
|
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week