Python3 中有六个标准的数据类型Number(数字)、 String(字符串)、 List(列表) 、Tuple(元组)、 Sets(集合) 、Dictionary(字典)
1.内置的 type() 函数可以用来查询变量所指的对象类型
2. isinstance来判断变量是否是某个类型
1 a=111 2 type(a) 3 print(type(a)) 4 print(isinstance(a,int)) 5 6 7 8 9 class A: 10 pass 11 12 class B(A): 13 pass 14 15 print(isinstance(A(), A)) 16 print(type(A()) == A) 17 print(isinstance(B(), A)) #type()不会认为子类是一种父类类型 18 print(type(B()) == A) #isinstance()会认为子类是一种父类类型 19 ------------------------------------------------------------------------------------- 20 <class ‘int‘> 21 True 22 23 24 True 25 True 26 True 27 False
1.对于某个类型或方法,操作:ctrl+鼠标左键 查询
1.print(dir(变量名))用来查询一个类或者对象的所有方法。
2.help(type(变量名))用来查询变量名能使用的方法的说明文档。
1 name=‘str‘ 2 print(dir(name)) #简列功能名称 3 help(type(name))#详细列出功能说明 4 ----------------------------------------------------------------------------------- 5 [‘__add__‘, ‘__class__‘, ‘__contains__‘, ‘__delattr__‘, ‘__dir__‘, ‘__doc__‘, ‘__eq__‘, ‘__format__‘, ‘__ge__‘, ‘__getattribute__‘, ‘__getitem__‘, ‘__getnewargs__‘, ‘__gt__‘, ‘__hash__‘, ‘__init__‘, ‘__init_subclass__‘, ‘__iter__‘, ‘__le__‘, ‘__len__‘, ‘__lt__‘, ‘__mod__‘, ‘__mul__‘, ‘__ne__‘, ‘__new__‘, ‘__reduce__‘, ‘__reduce_ex__‘, ‘__repr__‘, ‘__rmod__‘, ‘__rmul__‘, ‘__setattr__‘, ‘__sizeof__‘, ‘__str__‘, ‘__subclasshook__‘, ‘capitalize‘, ‘casefold‘, ‘center‘, ‘count‘, ‘encode‘, ‘endswith‘, ‘expandtabs‘, ‘find‘, ‘format‘, ‘format_map‘, ‘index‘, ‘isalnum‘, ‘isalpha‘, ‘isdecimal‘, ‘isdigit‘, ‘isidentifier‘, ‘islower‘, ‘isnumeric‘, ‘isprintable‘, ‘isspace‘, ‘istitle‘, ‘isupper‘, ‘join‘, ‘ljust‘, ‘lower‘, ‘lstrip‘, ‘maketrans‘, ‘partition‘, ‘replace‘, ‘rfind‘, ‘rindex‘, ‘rjust‘, ‘rpartition‘, ‘rsplit‘, ‘rstrip‘, ‘split‘, ‘splitlines‘, ‘startswith‘, ‘strip‘, ‘swapcase‘, ‘title‘, ‘translate‘, ‘upper‘, ‘zfill‘] 6 Help on class str in module builtins: 7 8 class str(object) 9 | str(object=‘‘) -> str 10 | str(bytes_or_buffer[, encoding[, errors]]) -> str 11 | 12 | Create a new string object from the give 13 14 。。。。。。。。。 15 。。。。
1 var1=1;var2=10 2 print(var1,var2) 3 del var1,var2#del语句删除单个或多个对象 4 5 6 7 8 var1 =[‘333‘,‘5555‘,‘22222‘] 9 print(var1) 10 del var1[2] 11 print(var1)#使用del语句删除一些对象引用 12 13 --------------------------------------------------------------------- 14 1 10 15 16 17 18 19 [‘333‘, ‘5555‘, ‘22222‘] 20 [‘333‘, ‘5555‘]
1 a=111 2 print(id(a)) #查看内存地址 3 b=a #b=a则共同指向同一内存地址 4 print(id(a),id(b)) 5 c=111111111111111111111111111111 6 d=111111111111111111111111111111 7 print(id(c),id(d)) #python优化:一个数对应一个内存??? 8 --------------------------------------------------------------------------------- 9 1552800528 10 1552800528 1552800528 11 81990240 81990240
原文:https://www.cnblogs.com/yu-liang/p/8562083.html