mirror of
https://github.com/Asabeneh/30-Days-Of-Python.git
synced 2026-06-03 21:02:42 +08:00
some fixes
This commit is contained in:
parent
3115e10e69
commit
d9397d969f
BIN
images/list_index.png
Normal file
BIN
images/list_index.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
images/string_index.png
Normal file
BIN
images/string_index.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
@ -994,6 +994,9 @@ print(f) # n
|
||||
```
|
||||
#### Accessing characters in strings by index
|
||||
In programming counting starts from zero. Therefore the first letter of a string is at zero index and the last letter of a string is the length of a string minus one.
|
||||
|
||||

|
||||
|
||||
```py
|
||||
language = 'Python'
|
||||
first_letter = language[0]
|
||||
@ -1336,7 +1339,8 @@ Number of countries: 5
|
||||
lst = ['Asabeneh', 250, True, {'country':'Finland', 'city':'Helsinki'}] # list containing different data types
|
||||
```
|
||||
### Accessing list items using positive indexing
|
||||
We access each item in a list using their index. A list index start from 0.
|
||||
We access each item in a list using their index. A list index start from 0. The picture below show clearly where the index starts
|
||||

|
||||
```py
|
||||
fruits = ['banana', 'orange', 'mango', 'lemon']
|
||||
first_fruit = fruits[0] # we are accessing the first item using its index
|
||||
@ -1672,6 +1676,8 @@ ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24]
|
||||
29. Find the middle country(ies) in the [countries list](https://github.com/Asabeneh/30-Days-Of-Python/tree/master/data/countries.py)
|
||||
30. Divide the countries list into two equal lists if it is even if not one more country for the first half.
|
||||
|
||||
['banana', 'orange', 'mango', 'lemon']
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user