+ 1
Split generator
I don’t understand why I would ever go through the process of making a function and yielding a variable within to list a string when I can just do… String = “what is this”.split() print(string) Would that not give me the same result in less lines of code?
1 Antwort
0
Azi Bibbins
I believe the examples you were looking at was focusing on how to construct a function.
Tutorials tend to use previous lessons to promote knowledge and re-inforce concepts already learnt.
Remember, the main purpose of a function is that you can re-use the concept on many items without having to re-write the required code.
Your idea is great if you have only one list to deal with, but what if you have 1000 lists
functions and iterations will do the work for you.
Great question!