+ 1
Rising and For loops
Could someone explain how does these both things work? Thank you
1 Antwort
+ 1
I don't understand, what you mean by rising but I can explain for loop.....
for in python are similar to for loop in other language the difference is in syntax.....
Syntax :
for var in iterable:
code
Here var can be any variable, with holds the value of iterable at specific instance.....
Iterable can be any data type in python which contain can more then one primitive data type.....
To be specific iterable can be list, tuple, set, string or and any function which return more then one value....
Here iterable can replaced by any primitive data type....
e.g.
for i in range(5):
print(i)
# print 0 to 4 numbers....
l = [3,8,5,"he"]
for i in l:
print(i)
# print all element of l...
for loop are mostly used in list compression....
For creating list of element 0 to 5....
l = [i for i in range(6)]
or create list of upper case character in input.....
l = [i for i in input() if i.isupper()]
Please note : these are just examples, for loops have many more uses....