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"
print(age)
print(years_of_school)
We get the sames result...
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.
Best,
Tsvetelin