Python学习手册——笔记一

来源:互联网 发布:php 单引号 引用变量 编辑:程序博客网 时间:2024/05/21 02:19
Python常用类型
>>> a = 1>>> type(a)<class 'int'>>>> a = 1.0>>> type(a)<class 'float'>>>> a = 'abcd'>>> type(a)<class 'str'>>>> a = (1,2)>>> type(a)<class 'tuple'>>>> a = [1, 2];>>> type(a)<class 'list'>>>> a = {1, 2}>>> type(a)<class 'set'>>>> a = {1:1, 2:2}>>> type(a)<class 'dict'>

其中list、set、dict为可变类型还有一个关于Python对象引用的困惑的例子。明白了这个对象引用就理解了。
>>> S1 = 'spam'>>> S2 = 'spam'>>> S1 == S2, S1 is S2(True, True)>>> S1 = 'a longer string'>>> S2 = 'a longer string'>>> S1 == S2, S1 is S2(True, False)