Python3 programming first step

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

Instance (Python 3.0+)

#!/usr/bin/python3 # Fibonacci series: Fibonacci sequence # The sum of the two elements determines the next number a, b< Span class="hl-code"> = 0, 1 while b < 10: print(b< Span class="hl-brackets">) a, b< Span class="hl-code"> = b, a+b

The code a, b = b, a+b is calculated by first calculating the right expression and then assigning it to the left, equivalent to:


Execute the above program, the output is:


This example introduces several new features.

The first line contains a compound assignment: the variables a and b get the new values 0 and 1 at the same time. The last line uses the same method again, and you can see that the expression on the right will be executed before the assignment changes. The order of execution of the right expression is from left to right.

Output variable value:

>>> i = 256*256
>>> print('i Value:', i)
i Value: 65536

end Keyword

The keyword end can be used to output the result to the same line, or to add different characters at the end of the output, as shown in the following example:

Instance(Python 3.0+)

#!/usr/bin/python3 # Fibonacci series: Fibonacci series # The sum of the two elements determines the next number a, b = 0, 1 while b < 1000: print(b, end=',') a, b = b, a+b

Execute the above program, the output is:


welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.