Week 5a - Mouse input and more lists----learning notes

pyton 程序内容的颠倒,运用 [](列表)

def reverse_string(s):
    """Returns the reversal of the given string."""
    result = ""
    for char in s:
        result = char + result
    return result

print reverse_string("hello")


输出的效果是: “olleh


pyton 实现斐波那契数列

import math
a = [0, 1]
for i in range(1,41):
    a.append(a[-1] + a[-2])
print a





posted @ 2014-10-22 20:35  同叔练级之路  阅读(143)  评论(0编辑  收藏  举报