Introduction:
This Python code snippet shows you how to use a for loop to print each character of the word PYTHON separately. It is a simple example that demonstrates the process of iterating through a string and accessing each character.
Code:
#Print the characters in word PYTHON using for loop
for letter in 'PYTHON':
print(letter)
Logic:
- The code uses a for loop to iterate through the letters in the string “PYTHON”.
- For each letter, the print statement is executed to display it on the console.
Output:
>> P
>> Y
>> T
>> H
>> O
>> N