您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Python入门之走向编程第一步一个例子开始

2022/12/20 0:56:36发布44次查看
of course, we can use python for more complicated tasks than adding two and two together. for instance, we can write an initial sub-sequence of the fibonacci series as follows当然,我们可以使用python来完成比把两个和两个加在一起更复杂的任务。例如,我们可以写出斐波那契级数的初始子序列如下
>>> # fibonacci series:
... # the sum of two elements defines the next
... a, b = 0, 1
>>> while b < 10:
... print(b)
... a, b = b, a+b
...
1
1
2
3
5
8
the first line contains a multiple assignment: the variables a and b simultaneously get the new values 0 and 1. on the last line this is used again, demonstrating that the expressions on the right-hand side are all evaluated first before any of the assignments take place. the right-hand side expressions are evaluated from the left to the righ
第一行包含多个赋值:变量a和b同时获得新值0和1。在最后一行中,再次使用,表明在任何赋值发生之前首先对右边的表达式进行求值。右边表达式由左到右进行计算。
the while loop executes as long as the condition (here: b >> i = 256*256
>>> print('the value of i is', i)
the value of i is 65536
the keyword argument end can be used to avoid the newline after the output, or end the output with a different string:关键字参数结束可以用来避免输出后的换行符,或者用不同的字符串结束输出:
>>> 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,
footnotes:注意:
since ** has higher precedence than -, -3**2 will be interpreted as -(3**2) and thus result in -9. to avoid this and get 9, you can use (-3)**2.
由于**比-a具有更高的优先级,-*** 2将被解释为-(3**2),从而导致-9。为了避免这个问题,得到9,你可以使用(-3)** 2。
unlike other languages, special characters such as \n have the same meaning with both single ('...') and double (...) quotes. the only difference between the two is that within single quotes you don’t need to escape (but you have to escape \') and vice versa.不像其他语言,特殊字符如\与双单引号(‘...’)和双引号(“....”)有相同的作用,唯一的不同是在双单引号时您不需要避免双引号,但是要避免\',反之亦然。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product