Latest web development tutorials

The first step in programming Python3

In the previous tutorial we have learned some basic knowledge of grammar Python3, let's try to write a Fibonacci sequence.

Examples are as follows:

#!/usr/bin/python3

# Fibonacci series: 斐波纳契数列
# 两个元素的总和确定了下一个数
a, b = 0, 1
while b < 10:
    print(b)
    a, b = b, a+b

The above program, the output is:

1
1
2
3
5
8

This example introduces several new features.

  • The first line contains a compound assignment: the variables a and b simultaneously get the new values ​​0 and 1. The last line again used the same method, you can see, on the right of expression will be executed before the assignment change. The execution order of expression on the right is from left to right.
>>> i = 256*256
>>> print('i 的值为:', i)
i 的值为: 65536

end keywords

Keyword end can be used to output the results to the same line, or output at the end of the add different characters, examples are as follows:

#!/usr/bin/python3

# Fibonacci series: 斐波纳契数列
# 两个元素的总和确定了下一个数
a, b = 0, 1
while b < 1000:
    print(b, end=',')
    a, b = b, a+b

The above program, the output is:

1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,