本笔记参考《python编程:从入门到实践》一书
本书将Python3.7+环境搭建与终端运行第一个你好世界作为第一章
笔记并没有过多的记录所以略过了捏
数
print(2 + 3)
print(2 - 3)
print(2 / 3)
print(2 * 3)
print(2 ** 3)
print(2 + 3 * 4)
print((2 + 3) * 4)
print(2 * 0.1)
print(3 * 0.1)
Python 将所有带小数点的数成为浮点数。但需要注意的是,结果包含的小数位数可能不确定
无论是何总计算,只要有操作数是浮点数,Python 默认得到的总是浮点数,即便结果原本为整数
将两个数相除时,结果总是浮点数,即便这两个数都是整数且能整出。
在任何运算中,一个操作数是整数,另一个操作数是浮点数,结果也总是浮点数。
数中的下划线
number = 14_0000_0000
print(number)
常量
MAX_CONNECTIONS = 3000
print(MAX_CONNECTIONS)
all---大写
同时给多个变量赋值
a,b,c = 1,2,3
print(a)
print(b,c)
print(a,b,c)
注释
单行注释:Ctrl+/
多行注释:选中+Ctrl+/
python之禅
The Zen of Python
by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you’re Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea – let’s do more of those!