美文网首页
Python 练习实例32

Python 练习实例32

作者: loinue | 来源:发表于2022-04-08 07:32 被阅读0次

来自菜鸟教程
https://www.runoob.com/python/python-exercise-example32.html
题目:按相反的顺序输出列表的值。

程序分析:无。

程序源代码:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
a = ['one', 'two', 'three']
for i in a[::-1]:
    print (i)

以上实例输出结果为:

three
two
one

这里主要是使用了a[::-1]这种写法。
注意有两个冒号,说明有三个参数。前两个参数忽略。
最后一个参数用-1表示是倒数第一个。

相关文章

网友评论

      本文标题:Python 练习实例32

      本文链接:https://www.haomeiwen.com/subject/csxajrtx.html