Added outputs for examples (#20171)

This commit is contained in:
mistymayem
2018-10-18 18:59:04 -04:00
committed by Aditya
parent 5c9f60961c
commit 51c7b412a1

View File

@ -22,6 +22,14 @@ list_of_tuples = [(1,2), (3,4)]
for a, b in list_of_tuples:
print("a:", a, "b:", b)
```
Output:
```python
a: 1 b: 2
a: 3 b: 4
```
On the other hand, you can loop over anything that is iterable. You can call a function or use a list literal.
```python
@ -34,6 +42,17 @@ for character in ["P", "y", "t", "h", "o", "n"]:
print("Give me a '{}'!".format(character))
```
Output:
```python
Give me a 'P'!
Give me a 'y'!
Give me a 't'!
Give me a 'h'!
Give me a 'o'!
Give me a 'n'!
```
Some ways in which For loops are used:
**Iterate over the range() function**
@ -44,6 +63,7 @@ for i in range(10):
```
Rather than being a function, range is actually an immutable sequence type.
The output will contain results from lower bound i.e 0 to the upper bound i.e 10 but excluding 10.By default the lower bound or the starting index is set to zero.
Output:
```