The init method

The init method is a special method that gets invoked when an object is instantiated. Its full name is __init__ (two underscore characters, followed byinit, and then two more underscores). An init method for the Time class might look like:

def __init__(self,hour=0,minute=0,second=0):
        self.hour = hour
        self.minute = minute
        self.second = second

It is common for the parameters of __init__ to have the same names as the attributes. The parameters are optional, so if you call Time with no arguments, you get the default values. If you provide one argument, it overrides hour. If you provide two arguments, they override hour and minute. And if you provide three arguments, they override all three default values.

from Thinking in Python

时间: 2024-12-14 00:43:06

The init method的相关文章

java代码中init method和destroy method的三种使用方式

在java的实际开发过程中,我们可能常常需要使用到init method和destroy method,比如初始化一个对象(bean)后立即初始化(加载)一些数据,在销毁一个对象之前进行垃圾回收等等. 周末对这两个方法进行了一点学习和整理,倒也不是专门为了这两个方法,而是在巩固spring相关知识的时候提到了,然后感觉自己并不是很熟悉这个,便好好的了解一下. 根据特意的去了解后,发现实际上可以有三种方式来实现init method和destroy method. 要用这两个方法,自然先要知道这两

Objective-C's Init Method

初始化器在其他面向对象的语言中(比如Java)指的是构造器. Objective-C同样拥有对象构造器在init形式的方法中.不管如何,在Objc中这些方法没有什么特殊的行为. 按照惯例,程序猿在init方法中设置对象初始的状态,但是实际上它们和其他的Objc方法一样. 因为它们像任何其他的Objc方法,程序猿必须从init方法显示返回已初始化的对象.特别的,这些方法只是简单的返回它们的接收者(receiver)(常常在最后一行中以return self结尾),但是它也有可能返回一个完全不同的对

Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; neste

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: com.

SSH项目练习的时候报错:[applicationContext.xml]: Invocation of init method failed;

这里是控制台的报错信息:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingEx

Invocation of init method failed; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration

今天在用测试类做测试的,发起测试时候报错 :Error activating Bean Validation integration hibernate 配置数据源 <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close"> <property name="driverClassName&q

Spring Boot报错Error creating bean with name &#39;userRepository&#39;: Invocation of init method failed; nested exception

问题:出现UserRePository注入创建失败,一定先检查所有的@注解是否已经标记 问题发现:entity下的实体类上面没有加注解  任何基于hibernate的实体类一定要加上@Entity注解! Spring Boot报错Error creating bean with name 'userRepository': Invocation of init method failed; nested exception 原文地址:https://www.cnblogs.com/my-prog

spring init

DN学院讲师招募     Markdown编辑器轻松写博文     TOP 50 CTO坐镇直招     读文章说感想获好礼 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作 分类: Spring 2013-03-16 16:48 24901人阅读 评论(1) 收藏 举报 关于在spring  容器初始化 bean 和销毁前所做的操作定义方式有三种: 第一种:通过@PostConstruct 和 @PreDestroy 方法

Q10:fatal error:use of unimplemented initializer init(nibName nibNameOrNil: String?, bundle nibBundl

init method 关键知识点 问题描述: fatal error: use of unimplemented initialer for class 代码二: import UIKit class ViewController:UIViewController{ var data:String? init(para:String){ //那么参数 放这里初始化呢 self.data = para super.init() //还是放这里初始化呢 self.data = para } req

Servlet init

我们从常用的HttpServlet来看. HttpServlet extends: GenericServlet All Implemented Interfaces: java.io.Serializable, Servlet, ServletConfig 接口Servlet中定义了init(ServletConfig)方法 init public void init(ServletConfig config) throws ServletException Called by the ser