编程常用英文单词

Python3 中常见的数据类型有:

Number(数字)
String(字符串)
bool(布尔类型)
List(列表)
Tuple(元组)
Set(集合)
Dictionary(字典)

不可变数据(3 个):Number(数字)、String(字符串)、Tuple(元组);
可变数据(3 个):List(列表)、Dictionary(字典)、Set(集合)。

int、float、bool、complex [ˈkɒmpleks](复数)

isinstance 和 type 判断数据类型

print /prɪnt/ (打印)
a, b, c, d = 20, 5.5, True, 4+3j
print(type(a), type(b), type(c), type(d))

 a = 111
 isinstance(a, int)

Python3 中,bool 是 int 的子类,True 和 False 可以和数字相加, True==1、False==0 会返回 True,但可以通过 is 来判断类型。

subclass /ˈsʌbˌklɑːs/  (子类)
SyntaxWarning(语法警告)
Syntax  语法 [´sɪnˌtæks]
Warning 警告 [ˈwɔːnɪŋ]
>>> issubclass(bool, int) 
True
>>> True==1
True
>>> False==0
True
>>> True+1
2
>>> False+1
1
>>> 1 is True
<python-input-12>:1: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  1 is True
False
>>> 0 is False
<python-input-13>:1: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  0 is False
False

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容