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 !
-

Hub USB 3.0 OBERSTER Multiport
€ 7,00 Acheter le produit -
Promo !

Routeur WiFi AX 3000 Mbps TP-Link Routeur, WiFi 6, 4 antennes à haute performance, OneMesh, WPA3
Le prix initial était : € 99,00.€ 56,00Le prix actuel est : € 56,00. Acheter le produit -

POO: Cours et exercices en UML2, Python, PHP, C#, C++ et Java (French Edition)
€ 17,00 Achetez le livre
1 thought on “Solution Exercise 16 iterate through the characters of a string in Python”