+ 1

What does .split do?

s1=‘It\’s cool to earn money’ s2=s1.split What is the result of this?

1st Jan 2018, 11:14 AM
Arfaan
Arfaan - avatar
4 RĂ©ponses
+ 8
Provided that those will be single quotes and not gravises, the command: puts s2 should split the string and print out each word in a separate line: It's cool to earn money while: print s2 prints a list, with each of the words as elements: ["It's", "cool", "to", "earn", "money"]
1st Jan 2018, 11:26 AM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 6
Shortly speaking - it transforms a string into a list of its separated (split) elements.
1st Jan 2018, 11:37 AM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
0
I kinda don’t get it. Could you please enter the result?
1st Jan 2018, 11:27 AM
Arfaan
Arfaan - avatar
0
Oh ok I think I get it now thanks
1st Jan 2018, 11:55 AM
Arfaan
Arfaan - avatar