__init__() 是类的内置方法,用于初始化类的内部状态,当我们去实例化一个对象的时候,默认就会执行 __init__() 下面的语句,例子如下:

#!/usr/bin/env python
#-*- coding:utf- -*- class People(object):
def __init__(self):
self.name = 'Tom'
self.age =
self.talk() def talk(self):
print('My name is %s' % self.name)
print('My age is %s' % self.age) if __name__ == '__main__':
obj = People()
[root@localhost ~]$ python .py
My name is Tom
My age is

__init__()的更多相关文章

  1. Python类中super()和__init__()的关系

    Python类中super()和__init__()的关系 1.单继承时super()和__init__()实现的功能是类似的 class Base(object): def __init__(sel ...

  2. python中__init__问题

    python中安装目录中的Lib文件夹模块中的__init__.py文件(文件内容可以为空),用于标识此文件夹是一个模块 python编程中的__init__表示初始化

  3. senlin __init__() got an unexpected keyword argument 'additional_headers'

    从senlin源码重新编译更新了服务,然后执行 senlin的 cli就遇到了错误: __init__() got an unexpected keyword argument 'additional ...

  4. python类中super()和__init__()的区别

    class Base(object):     def __init__(self): print 'Base create' class childB(Base): def __init__(sel ...

  5. Python中__init__方法

      注意1.__init__并不相当于C#中的构造函数,执行它的时候,实例已构造出来了. 1 2 3 4 5 class A(object):     def __init__(self,name): ...

  6. python面向对象中的__init__方法怎么理解?

    我们在学习python类的时候,总会碰见书上的类中有__init__()这样一个函数,很多同学百思不得其解,其实它就是python的构造方法. 构造方法类似于类似init()这种初始化方法,来初始化新 ...

  7. python:how does subclass call baseclass's __init__()

    First, use baseclass's name to call __init__() I wrote code like this: and we can use 'super' too.

  8. Python中的__new__和__init__

    Python中的__new__和__init__ 写了这么多的class,现在才知道还有个__new__方法, 那么它和__init__有什么区别呢? class TestCls(): "& ...

  9. Python __init__.py 作用详解

    __init__.py 文件的作用是将文件夹变为一个Python模块,Python 中的每个模块的包中,都有__init__.py 文件. 通常__init__.py 文件为空,但是我们还可以为它增加 ...

  10. Python中的__init__和__new__介绍

    介绍 首先我们要知道在面向对象编程中,实例化基本遵循创建实例对象.初始化实例对象.最后返回实例对象这么一个过程. Python 中的 __new__ 方法负责创建一个实例对象,__init__ 方法负 ...

随机推荐

  1. 【LeetCode】114. Flatten Binary Tree to Linked List

    Flatten Binary Tree to Linked List Given a binary tree, flatten it to a linked list in-place. For ex ...

  2. C#:Application操作(待补充)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. OpenSAML2.X 在SSO系统中的应用

    背景 年底的时候有机会开发一个SPA(单页面应用)的项目,那时候须要用到票据的方式能够用Cookie的方式来登录.当是想到了OpenID或者是CAS的方式来做统一认证中心.后来一个安全界的大牛推荐让我 ...

  4. tp配置+路由+基本操作

    一.打开apache 的配置文件httpd_conf添加以下代码 <VirtualHost *:80>DocumentRoot "D:\wwwroot\thinkphp\publ ...

  5. mysql的show操作

    SHOW CHARACTER SET 显示所有可用的字符集 SHOW CHARACTER SET; SHOW CHARACTER SET LIKE 'latin%'; SHOW COLLATION 输 ...

  6. unity, 由Matrix4x4提取Quaternion和Vector3 及 由Quaternion,Vector3构造Matrix4x4

    一,由Matrix4x4提取Quaternion和Vector3 Quaternion getRotationFromMatrix(Matrix4x4 m) {         return Quat ...

  7. 关于C与python交互设想及文章汇总

    gui: gtk by c 后台: python Python实例浅谈之三Python与C/C++相互调用 Python 与 C/C++ 交互的几种方式 C语言 + GTK3+ Visual Stud ...

  8. python-爬图小样

    python-爬某页面图 注意:python3+版本与python2有一定区别,需要注意多点. #! /usr/bin/env python3.5.4 # coding=utf-8 # 爬百度某贴吧页 ...

  9. CSS3 Flex布局(伸缩布局盒模型)学习

    CSS3 Flex布局(伸缩布局盒模型)学习 转自:http://www.xifengxx.com/web-front-end/1408.html CSS2定义了四种布局:块布局.行内布局.表格布局盒 ...

  10. 入门基础之——flash

    不得不说韦老师的课程还是很需要时间去消化.今天改变了学习策略,遇到不会的知识点,先查资料. 以前在单片机编程中,都只是知道代码存在flash中,而一听韦老师的课程,就是nand flash启动或者no ...