Python's for loop statement is similar to C++'s range for statement, similar to C#'s foreach loop traversal;
if you have not dabbled in the above two programming languages, please look forward from the back!
C++ range for statement:
string s = {
"HelloWorld!" };
for (auto str : s) {
cout <<"+" << str << endl;
}
Output result:
C#'s foreach loop traverses:
string s = "HelloWorld!";
foreach(var str in s)
{
Console.WriteLine($"#{str}");
}
Output result:
Python's for loop statement:
s="HelloWorld!"
for str in s:
print('p',str)
Output:
No amount of textual explanation is as good as a three-paragraph example.
Three pieces of code once again prove one thing: "Life is like a summer flower, Python prolongs life!"