python everything is object
python面向对象非常彻底,即使过程式的代码风格,python在运作的时候也是面向对象的。everything is object。
差异
在面向对象的理念上,python和非常工程化的面向对象语言(C++、Java、C#)有巨大的差异,这些语言,为了解释他们的原理,往往会祭出一大杀器-----内存模型。用单纯的、非常过称化的说明原理运行过程。(当然我并没有说这个有什么不好,这样是比较直接、简单的。)python讲到最深处,它会给你讲很多对象的故事。除非要深入解释器,如果深入解释器,那又是C++、Java、C#的事情了。那我们讲一个非常深入而简单的例子,内存对象。5是一个数字,但也是一个对象,所有的对象都要受着python环境的管理,运行python命令
>>> id(5)
19867920
>>> dir(4)
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__', '__div__', '_
_divmod__', '__doc__', '__float__', '__floordiv__', '__format__', '__getattribute__', '__getnewargs_
_', '__hash__', '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', '__lshift__
', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__', '__pow
__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '
__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshi
ft__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '_
_subclasshook__', '__truediv__', '__trunc__', '__xor__', 'bit_length', 'conjugate', 'denominator', '
imag', 'numerator', 'real']
可以看到,python环境中数值4、5。也是是python的一个对象。具有普通对象一样的性质。差异最明显的地方,往往是我们忽视的地方。python的type也是一种对象(用type()尝试一下获取int,long,type),而int,long,str则是类型,是元数据。是语言解释不了的,而直接套用了硬件的一些理念。
好了讲了一些python在一些旮旯里边的东西,C++11好像是一门新的语言(好老了,今天刚刚了解了一下,auto、decltype和for的引入,才是让我现在觉得最舒服的地方啊)还没开始用C++11呢。比起以前的版本差异好大啊 。。。。我好落后啊。
python everything is object的更多相关文章
- Debug 路漫漫-11:Python: TypeError: 'generator' object is not subscriptable
调试程序,出现以下错误: Python: TypeError: 'generator' object is not subscriptable “在Python中,这种一边循环一边计算的机制,称为生成 ...
- python pip 'nonetype' object has no attribute 'bytes'
python pip 'nonetype' object has no attribute 'bytes' 更新 pip for Windows : python -m pip install -U ...
- Python TypeError: 'module' object is not callable 原因分析
今天尝试使用pprint进行输出,语句为 >>>import pprint >>>pprint(people) 结果报错,TypeError: 'module' o ...
- Python 中的object takes no parameters错误
Python是一门面向对象的语言,中我们首先创建一个类: class Student(object): def _init_(self,name,score): self.name = name se ...
- 【Python深入】Python中继承object和不继承object的区别
python中定义class的时候,有object和没有object的不同?例如: class Solution(object): class Solution(): 这俩的区别在于—————— 在p ...
- python: "TypeError: 'type' object is not subscriptable"
目前stackoverflow找到两种情况的解决办法: 1.TypeError: 'type' object is not subscriptable when indexing in to a di ...
- Python: TypeError: 'dict' object is not callable
问题: TypeError: 'dict' object is not callable 原因: dict()是python的一个内建函数,如果将dict自定义为一个python字典,在之后想调用 ...
- python 中的object与type的关系
object 和 type的关系很像鸡和蛋的关系,先有object还是先有type没法说,obejct和type是共生的关系,必须同时出现的. 在看下去之前,也要请先明白,在Python里面,所有的东 ...
- 【Python】unicode' object is not callable
在Python中,出现'unicode' object is not callable的错误一般是把字符串当做函数使用了.
随机推荐
- Google Map API 学习六-设置infoWindow的长宽
- 转 -- MVC+EF easyui dataGrid 动态加载分页表格
首先上javascript的代码 <script type="text/javascript"> $(function () { LoadGrid(); }) //加载 ...
- Delphi WebService 中 Web App Debugger 的建议
NEW一个WEBAPP,选WEBAPPDEBUGGER,输一个COCLASSNAME,比如叫HELLO保存为工程比如叫TEST,UNIT2比如改叫WEBMOD,UNIT1以后没用了,所以还叫UNIT1 ...
- 排序算法简介及其C实现
排序算法(Sorting Algorithm)是计算机算法的一个组成部分. 排序的目标是将一组数据 (即一个序列) 重新排列,排列后的数据符合从大到小 (或者从小到大) 的次序.这是古老但依然富有挑战 ...
- SWMM代码移植到64位平台
在32位平台上运行SWMM模型,当节点数量到达60万以上的时候,模型运行占用内存接近1.85G的时候就会因为内存不够而无法计算.这种情况还是单独运行SWMM.exe的时候出现,如果采用SWMM.DLL ...
- Sicily1059-Exocenter of a Trian
代码地址: https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1059.c 1059. Exocenter of a ...
- Sicily1151:魔板搜索及优化
最终优化代码地址: https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1151.c 题目如下 Constraints ...
- How to install Python 2.7 and Python 3.3 on CentOS 6
原文地址:http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/
- (转)Linux中的文件描述符
本文转自:http://blog.csdn.net/cywosp/article/details/38965239 作者:cywosp 1. 概述 在Linux系统中一切皆可以看成是文件,文件又可分为 ...
- [NOIP2015pj题解]From某因为时间快了那么一点点超过下一位的蒟蒻(其实是纯代码).
第一题,很水,直接上代码 #include <iostream> #include <fstream> #include <cstdlib> /* run this ...