函數:
# -*- coding:utf-8 -*-
def my_abs(x):
if x >= 0:
return x
else:
return -x
print u'請輸入數字:'
x=raw_input()
xx = my_abs(int(x))
print u'%s的絕對值是%d' %(x,xx)
列表生成式:
L = ['Hello', 'World', 18, 'Apple', None]
print [s.lower() if isinstance(s,str) else s for s in L ]
generator--生成器:
# -*- coding:utf-8 -*-
def fib(max):
n, a, b = 0, 0, 1
while n < max:
print b
a, b = b, a + b
n = n + 1
print fib(7)