Exercise 16
Write a python program to display all characters of a string variable. Example for s = "Python", the program displays the characters:
P
y
t
h
o
n
Solution (First method)
1 2 3 4 5 6 7 8 9 |
# Ask the user to enter a string variable s s = input("Enter a string of characters s: ") # get the length of s n = len(s) # display all characters of s for i in range(0, n): print(s[i]) |
Solution (second method)
1 2 3 4 5 6 |
# Ask the user to enter a string variable s s = input("Type a string of characters s: ") # display all characters of s for x in s: print(x) |
Younes Derfoufi
CRMEF OUJDA
Acheter sur Très Facile !
-
Guide Raspberry Pi - Pas à pas pour débutant
€ 14,00 Acheter le livre -
Apprendre Raspberry Pi : Série pour les Nuls 2ème édition
€ 24,00 Acheter le livre -
Promo !
TP-Link Routeur WiFi 6 Archer AX18** WiFi 6 nouvelle génération
Le prix initial était : € 40,00.€ 35,00Le prix actuel est : € 35,00. Acheter le produit
1 thought on “Solution Exercise 16 iterate through the characters of a string in Python”