Last answered:

21 Nov 2023

Posted on:

18 Nov 2023


Resolved: What's the point of split?

I was wondering what's the point of using .split(',')?

We can just use the next code :

(age,years_of_school) = "30","17"

We get the sames result...

1 answers ( 1 marked as helpful)
Posted on:

21 Nov 2023


Hi Rajaonarivony!
Thanks for reaching out.

Using .split(',') is useful when you have a single string containing multiple items separated by commas, and you want to split this string into separate elements. For example, if you have a string like "30,17", you can use "30,17".split(',') to split it into two separate strings "30" and "17".

In your example:

(age, years_of_school) = "30", "17"

You are already using two separate strings "30" and "17", so there's no need to split them. You have to use .split(',') when you start with a single string that needs to be divided into separate parts.

Hope this helps.

Submit an answer