菜鸟教程 -- 学的不仅是技术,更是梦想!

Python 基础教程
(追記) (追記ここまで)

Python 练习实例32

Python 100例 Python 100例

题目:按相反的顺序输出列表的值。

程序分析:无。

程序源代码:

实例

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

以上实例输出结果为:

three
two
one

Python 100例 Python 100例

AI 思考中...

6 篇笔记 写笔记

  1. #0

    叮咚

    a12***[email protected]

    3

    其他参考解法:

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    print '输入列表格式为:1,2,3,4'
    s=input()
    print type(s)
    a=list(s)
    print a[-1::-1]
    

    叮咚

    a12***[email protected]

    9年前 (2017年04月08日)
  2. #0

    不知道叫啥

    114***[email protected]

    22

    使用列表 reverse():

    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-
    list_ = ['a', 'b', 'c', 'd']
    list_.reverse()
    print( list_ )

    不知道叫啥

    114***[email protected]

    9年前 (2017年05月04日)
  3. #0

    Think_dfrent

    iwa***[email protected]

    3

    Python3实例,使用递归实现:

    #!/usr/bin/env python3
    a = ['one', 'two', 'three','four','five','six','seven','eight','nine','ten']
    def reverse(a):
     if len(a)<=1:
     print (a[0],end=" ")
     else:
     print(a[-1],end=" ")
     reverse(a[0:-1])
     
    reverse(a)

    Think_dfrent

    iwa***[email protected]

    9年前 (2017年06月19日)
  4. #0

    风过的时候

    lan***[email protected]

    3

    参考方法:

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    numlist = [100,1,23,4,5,6,6,7,7,8]
    for i in range(0,len(numlist)) :
     index = len(numlist)-i-1
     print(numlist[index])
    

    风过的时候

    lan***[email protected]

    9年前 (2017年07月21日)
  5. #0

    冰封心动

    107***[email protected]

    4

    参考:

    a = ['1','2','3']
    a.sort(reverse=True)
    for i in a:
     print(i)
    

    冰封心动

    107***[email protected]

    9年前 (2017年11月08日)
  6. #0

    爱吃零食的瘦子

    239***[email protected]

    3

    Python2.x 与 Python3.x均可用:

    numbers=list(range(1,10))
    reversed_list=[]
    for i in range(1,10):
     reversed_list.append(numbers.pop())
    print(reversed_list)

    爱吃零食的瘦子

    239***[email protected]

    9年前 (2017年11月22日)

点我分享笔记

  • 昵称 (必填)
  • 邮箱 (必填)
  • 引用地址

AltStyle によって変換されたページ (->オリジナル) /