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
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
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
![Filtering in a loop: example + exercise 3](https://i.ytimg.com/vi/7IKC4prx9CM/default.jpg)
![Grundkonzepte der Programmiersprache Python](https://i.ytimg.com/vi/vzJFXiDaBWA/default.jpg)
![Summing elements in a list using a loop "for" in Python: example + exercise 6](https://i.ytimg.com/vi/ZL75f3jqsAs/default.jpg)
![Konditionale Schritte in Python: Aufgabe 5](https://i.ytimg.com/vi/QbFLe2f1Nc8/default.jpg)
![Buscamos el valor mayor en una lista usando la palabra clave None en Python: ejemplo + ejercicio 11](https://i.ytimg.com/vi/nydOjKo28VU/default.jpg)
![Порядок выполнения действий в программировании и математике](https://i.ytimg.com/vi/6BQNYYHYGjA/default.jpg)
![Palabra clave "in" en Python. ¿Cómo aplicar "in" a strings en Python?](https://i.ytimg.com/vi/Ah_iaC8w6pA/default.jpg)
![Order of operations in programming and mathematics](https://i.ytimg.com/vi/8KVWbptzwj4/default.jpg)
![Counting elements in a list using a for loop in Python: example + exercise 5](https://i.ytimg.com/vi/vtS12NIoAWU/default.jpg)
![Structure "try and except" in Python: exercise 1 - a hotel](https://i.ytimg.com/vi/jltzq6YUpf0/default.jpg)
![Ejercicio: crear un while-bucle en Pyhton](https://i.ytimg.com/vi/E-N6SSmHGIs/default.jpg)
![Creación del bucle "for" en Python](https://i.ytimg.com/vi/j-24VLm1HAE/default.jpg)
![Упражнения на циклы в Python - проверьте себя](https://i.ytimg.com/vi/BK_LsClDm1Q/default.jpg)
![Python: la estructura del curso número 1](https://i.ytimg.com/vi/x63Ic81f6xM/default.jpg)
![Strings in Python. String concatenation in Python.](https://i.ytimg.com/vi/HbrGRoD0Uww/default.jpg)
![Python: Struktur des Kurses Nummer 1](https://i.ytimg.com/vi/Y8ZRyG9no2k/default.jpg)
![Индексы в строках в Python: оператор индексации [ ]](https://i.ytimg.com/vi/t_KpQr7MXxI/default.jpg)
![Variablen in Python](https://i.ytimg.com/vi/of1DqlZ6_UY/default.jpg)
![Bauen eigene Funktionen in Python: die Übung "Die Punktezahl und die Note"](https://i.ytimg.com/vi/I10mUBJCOK8/default.jpg)
![Johann Sebastian Bach: Sinfonia No. 4 in D Minor (BWV 790), celesta sound](https://i.ytimg.com/vi/SeCViPj1XtM/default.jpg)
![Como abrir y leer ficheros en Python](https://i.ytimg.com/vi/OsapBqsvLgU/default.jpg)