Загрузка страницы

Looping through strings in Python; examples + exercises

#python #stringspython #forloops #loopingthroughstrings

Exercises:

1. How many characters are there in these strings?

w = 'availability'

hd = 'All the king's horses and all the king's men couldn't put Humpty together again!'

2. How many letters

a
i
l

are there in the following string?

w = 'availability'

3. How many words king , apostrophes, letters a are there in the following string?

hd = 'All the king's horses and all the king's men couldn't put Humpty together again!'

Use a loop for to answer.

______________________________________________________________________________________

We already know how to loop through lists in Python, let's see how to loop through strings in Python. The algorithm of this looping is exactly the same.

String example:

f = 'kiwi'

We counted number of letters in this string, number of letters 'i' and demonstrated the index number of each letter of this string in Python.

Also we know when to replace the iteration variable by the underscore and how to apply len function to strings and to lists.

We created a new variable and named it LETTER_TO_CHECK in order to avoid a difficult situation with the letter 'i'.

Python course #2 in English 10
Python programming language course in English

#underscore #pythonexercises #pythontasks #python程式設計語言 #python程式設 #程式設計語言 #程式設

Видео Looping through strings in Python; examples + exercises канала Olga Soboleva
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
20 июля 2020 г. 20:06:55
00:17:16
Яндекс.Метрика