diff --git a/images/list_index.png b/images/list_index.png new file mode 100644 index 0000000..355324e Binary files /dev/null and b/images/list_index.png differ diff --git a/images/string_index.png b/images/string_index.png new file mode 100644 index 0000000..bf4c3f1 Binary files /dev/null and b/images/string_index.png differ diff --git a/readme.md b/readme.md index 4d9bd51..ad4bdf5 100644 --- a/readme.md +++ b/readme.md @@ -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. + + ![String index](./images/string_index.png) + ```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 +![List index](./images/list_index.png) ```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'] +