現在,我們能使用Python完成比 2+2 更復雜的工作。在下例里,我們能寫出一個初步的斐波納契數列如下:
>>> # Fibonacci series: 斐波納契數列 ... # 兩個元素的總和確定了下一個數 ... a, b = 0, 1 >>> while b < 10: ... print(b) ... a, b = b, a+b ... 1 1 2 3 5 8
這個例子介紹了幾個新特征。
>>> i = 256*256 >>> print('The value of i is', i) The value of i is 65536
關鍵字end可以被用于防止輸出新的一行,或者在輸出的末尾添加不同的字符:
>>> a, b = 0, 1 >>> while b < 1000: ... print(b, end=',') ... a, b = b, a+b ... 1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,