Python String | Crack()

Python Methods and Functions | String Variables

Syntax :

 str.split (separator, maxsplit) 

Parameters :

separator: The is a delimiter. The string splits at this specified separator. If is not provided then any white space is a separator.

maxsplit: It is a number, which tells us to split the string into maximum of provided number of times. If it is not provided then there is no limit.

specified separator. 

CODE 1

text = 'geeks for geeks'

  
# Split in Space

print (text.split ())

 

word = 'geeks, for, geeks'

  
# Divided into & # 39;, & # 39;

print (word.split ( ',' ))

 

word = 'geeks: for : geeks'

 
# Splitting into & # 39;: & # 39 ;

print (word.split ( ':' ))

 

word = 'CatBatSatFatOr'

 
# Splitting into 3

print ([word [i: i + 3 ] for i in range ( 0 , len (word), 3 )])

Output:

 ['geeks',' for', 'geeks'] [' geeks', 'for',' geeks'] ['geeks',' for', 'geeks'] [' Cat', 'Bat',' Sat', 'Fat',' Or'] 

Code 2

word = 'geeks, for, geeks, pawan'

 
# maxsplit: 0

print (word.split ( ', ' , 0 ))

 
# maxsplit: 4

print (word .split ( ',' , 4 ))

  
# maxsplit: 1

print (word.split ( ', ' , 1 ))

Output:

 ['geeks, for, geeks, pawan'] [' geeks', 'for',' geeks', 'pawan'] [' geeks', 'for, geeks, pawan' ]