在python中,一切皆对象,应该怎么理解呢??
先来看几个例子:
[root@localhost ~]# python3
Python 3.6.3rc1 (default, Feb 26 2018, 22:34:25)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 1 # 定义一个变量,值为1
>>> type(a) # 查看变量a的类型,可以看出变量a是由int类实例而来
<class 'int'>
>>> type(1) # 查看整数1的类型,结果也是由int类实例而来
<class 'int'>
>>> type(int) # 查看int类的类型,得出结论:int类型是由type类实例化而来
<class 'type'>
>>>
>>> str1 = 'aa' # 定义一个变量,值为'aa'字符串
>>> type(str1) # 查看变量str1的类型,可以看出变量str1是由str类实