python基础

python基础

2020.10.7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
r'xxx' ----xxx不发生转义    ('\'转义字符)

100000 ---等价于100_000,添加'_':'_'位置可以任意

浮点数:1.23x10^9 1.23e9
1.23x10^-9 1.23e-9 (e可以大小写)

'''...'''表示多行内容

布尔值 True False (首字符大写)
可进行 and、or、not运算

空值None(不等于0,0有自己的意义)
TODO可以创建自定义数据类型

变量:同一个变量可以反复被赋值,可为不同数据类型
a = 123 # a是整数
print(a)
a = 'ABC' # a变为字符串
print(a)
结果:
123
ABC

常量;变量名默认为全部大写

整数的运算结果永远是精确的,无论整数做//除法还是取余数,结果永远是整数
10/5=2.0
10//5=2
10%3=1

python的整数没有大小限制;
浮点数也没有,但超出一定范围(贼大)就直接表示为inf(无限大)

字符串和编码:

tip

1
2
3
4
5
6
7
8
9
10
11
12
字符串:
对于单个字符的编码,Python提供了ord()函数获取字符的整数表示,chr()函数把编码转换为对应的字符:
>>> ord('A')
65
>>> ord('中')
20013
>>> chr(66)
'B'
>>> chr(25991)
'文'

需要转义,用%%来表示一个%;
Author

John Doe

Posted on

2021-03-24

Updated on

2021-03-30

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Comments

You forgot to set the shortname for Disqus. Please set it in _config.yml.