Home > Backend Development > Python Tutorial > How to output the letters of a word in python

How to output the letters of a word in python

(*-*)浩
Release: 2019-07-20 09:02:39
Original
8931 people have browsed it

Python for loop can iterate over any sequence of items, such as a list or a string.

How to output the letters of a word in python

Grammar: (Recommended learning: Python video tutorial)

For loop syntax The format is as follows:

for iterating_var in sequence:
   statements(s)
Copy after login

Python can use a for loop to output the letters of the word.

Please take a look at the following examples:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
for letter in 'Python':     # 第一个实例
   print '当前字母 :', letter
 
fruits = ['banana', 'apple',  'mango']
for fruit in fruits:        # 第二个实例
   print '当前水果 :', fruit
 
print "Good bye!"
Copy after login

Output results of the above examples:

当前字母 : P
当前字母 : y
当前字母 : t
当前字母 : h
当前字母 : o
当前字母 : n
当前水果 : banana
当前水果 : apple
当前水果 : mango
Good bye!
Copy after login

For more Python related technical articles, please visit PythonTutorial column to learn!

The above is the detailed content of How to output the letters of a word in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template