MENU
Question -

Define split( ) with suitable example.



Answer -

The method split( ) returns a list of all the words in the string, using str as the separator (splits on all whitespace if left unspecified), optionally limiting the number of splits to num.
Syntax
str.split(str=тАЭтАЭ, num=string.count(str)).
Parameters
str тАФ This is any delimeter, by default it is space.
num тАФ This is number of lines to be made.
Example
# !/usr/bin/python
str = тАЬLinel-abcdef \nLine2-abc \nLine4-abcdтАЭ;
print str.split( ); print str.split(тАШ 1 );
OUTPUT
[тАШLinel-abcdefтАЩ, тАШLine2-abcтАЩ, тАШLine4-abcdтАЩ]
[тАШLinel-abcdefтАЩ, тАШ\nLine2-abc \nLine4-abcdтАЩ]

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×