鱼C论坛

 找回密码
 立即注册
查看: 1319|回复: 0

[技术交流] Justin和Python一起的几十天

[复制链接]
发表于 2017-7-20 22:13:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
005006知识要点

1.        E记法:2.5e4=2.5*10^4=25000【float类型】
2.        数据类型:int,str,bool,float
3.        判断数据类型:type(),isinstance()
type():
>>> type (520)
<class 'int'>
>>> type (2.5e10)
<class 'float'>
>>> type (True)
<class 'bool'>

isinstance():
>>> isinstance (520, int)
True
>>> isinstance('Justin',str)
True
>>> isinstance (3>2, bool)
True

4.        s为字符串   
s.isalnum()   所有字符都是数字或者字母,为真返回 Ture,否则返回 False。
s.isalpha()    所有字符都是字母,为真返回 Ture,否则返回 False。
s.isdigit()     所有字符都是数字,为真返回 Ture,否则返回 False。
s.islower()    所有字符都是小写,为真返回 Ture,否则返回 False。
s.isupper()   所有字符都是大写,为真返回 Ture,否则返回 False。
s.istitle()      所有单词都是首字母大写,为真返回 Ture,否则返回 False。
s.isspace()   所有字符都是空白字符,为真返回 Ture,否则返回 False。

5.        地板除法(floor)向下取整
10//8=1
10.0//8=1.0
10/8=1.25
10.0/2=5.

6.        运算符优先级
**表示幂:3**2=9
**优先级比其左侧的一元运算符优先级高,比右侧的低:-3**2=-9,2**-1=0.5

7.        【习题】求解:not 1 or 0 and 1 or 3 and 4 or 5 and 6 or 7 and 8 and 9   
如果你的回答是 0,那么小甲鱼很开心你中招了! 答案是:4   
not or and 的优先级是不同的:not > and > or   
我们按照优先级给它们加上括号:
(not 1) or (0 and 1) or (3 and 4) or (5 and 6) or (7 and 8 and 9)
== 0 or 0 or 4 or 6 or 9
== 4   
原因:短路逻辑 :3 and 4 == 4,而 3 or 4 == 3。

评分

参与人数 1鱼币 +3 收起 理由
小甲鱼 + 3

查看全部评分

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-27 05:09

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表