1. 变量和基本表达式
    1. 变量在它第一次赋值时创建。
    2. 变量在表达式中使用将被替换为它们的值。
    3. 变量在表达式中使用以前必须已赋值
    4. 变量像对象一样不需要在一开始进行声明

    换句话说,这些赋值会让变量a和b自动生成。

    #ipython3
    
    In [1]: a = 3
    
    In [2]: b = 4
    
    In [3]: a + 1,a - 1  
    Out[3]: (4, 2)
    
    In [4]: b * 3,b / 2
    Out[4]: (12, 2.0)
    
    In [5]: a % 2,b ** 2
    Out[5]: (1, 16)
    
    In [6]: b / 2 + a
    Out[6]: 5.0
    
    In [7]: print(b / (2.0 + a))
    0.8
    
  2. 数字显示的格式
    In [1]: num = 1 / 3.0
    
    In [2]: num
    Out[2]: 0.3333333333333333
    
    In [3]: print(num)
    0.3333333333333333
    
    In [4]: '%e' % num
    Out[4]: '3.333333e-01'
    
    In [5]: '%4.2f' % num
    Out[5]: '0.33'
    
    In [6]: '{0:4.2f}'.format(num)
    Out[6]: '0.33'
    

    这些方法的最后三个使用了字符串格式化,这是灵活地进行格式化的一种工具。

    In [1]: num = 1 / 3
    
    In [2]: repr(num)
    Out[2]: '0.3333333333333333'
    
    In [3]: str(num)
    Out[3]: '0.3333333333333333'
    

    这两个函数都会把任意对象变换成它们的字符串表示,repr默认的交互式回显,str转变为一种通常对用户更加友好的格式。一些对象两种格式都 有,str用于一般用途,repr用于额外的细节。这个概念将会为字符串以及类中的运算符重载做好铺垫。除了为任意对象提供打印字符串,str内置函数也 是字符串数据类型的名字,并且能够用一个编码的名字来调用,从而从一个字节字符串解码一个Unicode字符串。

  3. 比较:一般的和连续的一般的比较对数字起作用,它们比较操作数的相对大小,并返回一个布尔类型的结果。
    In [1]: 1 < 2
    Out[1]: True
    
    In [2]: 2.0 >= 1
    Out[2]: True
    
    In [3]: 2.0 == 2.0
    Out[3]: True
    
    In [4]: 2.0 != 2.0
    Out[4]: False
    

    连续比较

    In [1]: x = 2
    
    In [2]: y = 4
    
    In [3]: z = 6
    
    In [4]: x < y < z
    Out[4]: True
    
    In [5]: x < y and y < z
    Out[5]: True
    
    In [6]: x < y > z
    Out[6]: False
    
    In [7]: x < y and y > z
    Out[7]: False
    
    In [8]: 1 < 2 < 3.0 < 4
    Out[8]: True
    
    In [9]: 1 > 2 > 3.0 > 4
    Out[9]: False
    
    In [10]: 1 == 2 < 3
    Out[10]: False
    
  4. 除法:真除法,Floor除法,传统除法在Python3中,传统除法已经基本被真除法兼并
    	
    In [1]: 10 / 4
    Out[1]: 2.5
    
    In [2]: 10 // 4
    Out[2]: 2
    
    In [3]: 10 / 4.0
    Out[3]: 2.5
    
    In [4]: 10 // 4.0
    Out[4]: 2.0
    

    /执行真除法,不管操作数的类型,总是返回包含任何余数的一个浮点结果

    //执行Floor除法,它截取掉余数并且针对整数操作数返回一个结果,但如果有任何一个操作数是浮点类型,则返回一个浮点数。//的结果数据类型总是依赖于操作数的类型。

    In [1]: (5 / 2),(5 / 2.0),(5 / -2.0),(5 / -2)
    Out[1]: (2.5, 2.5, -2.5, -2.5)
    
    In [2]: (5 // 2),(5 // 2.0),(5 // -2.0),(5 // -2)
    Out[2]: (2, 2.0, -3.0, -3)
    
    In [3]: (9 / 3),(9.0 / 3),(9 // 3),(9 // 3.0)
    Out[3]: (3.0, 3.0, 3, 3.0)
    

    注意负数的情况,Floor除法把结果向下截断到它的下层!即真正结果之下的最新的整数。其直接效果是向下舍入,并不是严格地截断!也不是四舍五入!

  5. 复数在Python中,复数是个不同的核心对象类型。复数表示为两个浮点数(实部和虚部)并接在虚部增加了i或者j的后缀。我们能够把非零实部的复数写成由+连接起来的两部分。
    In [1]: 1j * 1J
    Out[1]: (-1+0j)
    
    In [2]: 2 + 1j * 3
    Out[2]: (2+3j)
    
    In [3]: (2 + 1j) * 3
    Out[3]: (6+3j)
    

    复数允许我们分解出它的实部和虚部作为属性,并支持所有一般的数学表达式,并且可以通过标准的cmath模块(复数版的标志数学模块)中的工具进行处理。

  6. 十六进制,八进制和二进制计数Python默认地用十进制值显示。如下常量编码会产生具有三种进制的指定值的常规整数。
    In [1]: 0o1,0o20,0o377
    Out[1]: (1, 16, 255)
    
    In [2]: 0x01,0x10,0xFF
    Out[2]: (1, 16, 255)
    
    In [3]: 0b1,0b10000,0b11111111
    Out[3]: (1, 16, 255)
    

    我们可以通过内置函数,将整数转换为其它进制的数字字符串

    In [1]: oct(64),hex(64),bin(64)
    Out[1]: ('0o100', '0x40', '0b1000000')
    

    内置的int函数会将一个数字的字符串变换为一个整数,并可以通过第二个参数来确定变换后的数字的进制

    In [2]: int('64'),int('100',8),int('40',16),int('1000000',2)
    Out[2]: (64, 64, 64, 64)
    
    In [3]: int('0x40',16),int('0b1000000',2) 
    Out[3]: (64, 64)
    

    你能够使用字符串格式化方法调用和表达式将一个整数转换成八进制数和十六进制数的字符串

    In [1]: '{0:o},{1:x},{2:b}'.format(64,64,64)
    Out[1]: '100,40,1000000'
    
    In [2]: '%o,%x,%X' % (64,255,255)
    Out[2]: '100,ff,FF'
    
分类: Python3

78 条评论

canadaasians.com · 2026-09-07 11:12

References:

Online pokies pay id canadaasians.com

jackpot pokies payid · 2026-09-17 20:17

References:

Play online pokies payid australia jackpot pokies payid

payid pokies online · 2026-09-17 22:42

References:

Online pokies that accept payid https://manualshyundai.com/user/testtrade98/

secure payid pokies · 2026-09-18 01:28

References:

Payid pokies real money no deposit http://wou.malaysia2host.com/home.php?mod=space&uid=329326

https://cdss.snw999.com · 2026-09-18 03:06

References:

Payid pokies no deposit bonus https://cdss.snw999.com/space-uid-2556070.html

new payid pokies australia · 2026-09-18 12:19

References:

Payid deposit online pokies https://guzhen0552.cn/home.php?mod=space&uid=2518778

test-sida.noads.biz · 2026-09-20 00:42

References:

Direct bank transfer payout casino https://test-sida.noads.biz/?449742

downarchive.org · 2026-09-20 01:46

References:

Neosurf casino tips australia http://downarchive.org/user/bodycarp31/

Casino mit Sofort Einzahlung · 2026-09-21 10:37

References:

Casino sofort echtgeld https://aryba.kg/user/soccerboy0/

online casino sofortüberweisung · 2026-09-21 20:25

References:

Sofortüberweisung casino erfahrungen https://may22.ru/user/yarnfrance7/

dobryakschool.ru · 2026-09-21 23:45

References:

Spielothek sofortüberweisung klarna https://dobryakschool.ru/user/arrowfrance0/

https://undrtone.com · 2026-09-22 00:08

References:

Sofort Casino Alternativen https://undrtone.com/brickwallet8

vseapsny.ru · 2026-09-22 04:33

References:

Online casino sofort einzahlung https://vseapsny.ru/user/inputbeef7/

https://molchanovonews.ru/ · 2026-09-22 04:41

References:

Online casino mindesteinzahlung sofort https://molchanovonews.ru/user/pagegum4/

pad.public.cat · 2026-09-22 06:07

References:

Sofort Casino Einzahlungslimit https://pad.public.cat/m7bRtDVCSqegwKeHwswgZQ

sofort online casino · 2026-09-23 02:09

References:

Top Sofortüberweisung Casinos https://www.88m2.com/?301471

online casino payid pokies · 2026-09-23 02:40

References:

Free spins payid pokies australia https://dudoser.com/user/listpain49/

bbs.kxwh.cn · 2026-09-23 02:50

References:

Casino sofort vergleich https://bbs.kxwh.cn/home.php?mod=space&uid=417269

https://www.brainchips.liuyanze.com/ · 2026-09-23 02:51

References:

Online casino sofortüberweisung ab 1 euro https://www.brainchips.liuyanze.com/?313202

pokies payid instant · 2026-09-23 03:27

References:

Payid pokies real money no deposit http://bbs.lotsmall.cn/home.php?mod=space&uid=616027

http://www.pshunv.com · 2026-09-23 03:32

References:

Online Casino Klarna Sofortüberweisung http://www.pshunv.com/space-uid-960873.html

bbs.kxwh.cn · 2026-09-23 03:59

References:

Online Casinos mit Sofortüberweisung https://bbs.kxwh.cn/home.php?mod=space&uid=417271

https://www.forum.uookle.com · 2026-09-23 06:08

References:

Casino 1 euro einzahlung sofortüberweisung https://www.forum.uookle.com/home.php?mod=space&uid=1801882

same day payout pokies payid · 2026-09-23 07:38

References:

Instant withdrawal payid pokies http://alfa-power.de/member.php?action=profile&uid=83880

8njy.com · 2026-09-23 08:45

References:

Casino 1 euro einzahlung sofortüberweisung https://www.8njy.com/home.php?mod=space&uid=162121

casino sofort deutschland · 2026-09-23 09:53

References:

Sofortüberweisung casino ohne oasis http://wargame-workshop.com/bbs/home.php?mod=space&uid=1452222

Sofortüberweisung Casino Anleitung · 2026-09-23 10:14

References:

Spielautomaten sofortüberweisung https://cdss.snw999.com/space-uid-2647304.html

xiuwushidai.com · 2026-09-23 10:37

References:

Online casino app sofortüberweisung https://www.xiuwushidai.com/home.php?mod=space&uid=2901871

forum.uookle.com · 2026-09-23 11:43

References:

Neue Online Casinos mit Sofort https://www.forum.uookle.com/home.php?mod=space&uid=1801860

https://www.88m2.com/?301328 · 2026-09-23 11:50

References:

Sofortüberweisung casino erfahrungen https://www.88m2.com/?301328

http://xhdyz.cn/ · 2026-09-23 12:03

References:

Bestes Sofortüberweisung Casino http://xhdyz.cn/home.php?mod=space&uid=1174228

9youro.com · 2026-09-23 12:04

References:

Casino 10 euro einzahlung sofortüberweisung http://9youro.com/home.php?mod=space&uid=111091

bbs.91tata.com · 2026-09-23 12:17

References:

Sofort casino deutschland http://bbs.91tata.com/?16701549

www.seafishzone.com · 2026-09-23 16:53

References:

Sofortüberweisung Echtgeld Casino http://www.seafishzone.com/home.php?mod=space&uid=3243674

http://www.bzsbs.cn · 2026-09-23 16:59

References:

Casino sofort ohne anmeldung http://www.bzsbs.cn/home.php?mod=space&uid=1320620

sofortüberweisung casino ohne oasis · 2026-09-23 18:05

References:

Online casino sofort http://www.qilurexian.net/?241508

nlvbang.com · 2026-09-23 20:07

References:

Sofortüberweisung casino ohne registrierung https://www.nlvbang.com/home.php?mod=space&uid=3238569

http://bbs.lotsmall.cn/home.php?mod=space&uid=653278 · 2026-09-23 20:53

References:

Casino ohne mindesteinzahlung sofortüberweisung http://bbs.lotsmall.cn/home.php?mod=space&uid=653278

bzsbs.cn · 2026-09-24 00:51

References:

Sofort Casino Echtgeld http://www.bzsbs.cn/home.php?mod=space&uid=1320592

http://xhdyz.cn/home.php?mod=space&uid=1174116 · 2026-09-24 01:10

References:

Sofortüberweisung Einzahlung Casino http://xhdyz.cn/home.php?mod=space&uid=1174116

bbs.88moli.top · 2026-09-24 02:39

References:

Sofortüberweisung Einzahlung Casino http://bbs.88moli.top/home.php?mod=space&uid=128553

发表回复

Avatar placeholder

您的邮箱地址不会被公开。 必填项已用 * 标注