2010年6月25日 星期五

what is __init__? and what are classes and objects?

what is __init__? and what are classes and objects?

init is an abbreviation for initialization.

For instance if I have a Point class... that has two objects which are the x and y coordinates i can do this:


class Point():
pass

point = Point()
point.x = 3.0
point.y = 4.0


so instead you can do this:


class Point():
def __init__(self, x=0,y=0):
self.x = x
self.y = y


now you can make a point like this:

point = Point(3,4)

or

point = Point() # which gives you a point of default 0,0 .

Reference :
http://ubuntuforums.org/archive/index.php/t-540438.html

Related Posts:

  • ping commandDescripton :Use ping to ping other computer.Make sure it is alive.Design method : +------+ … Read More
  • Ping - threadDescription :Use ping to determine the ip address is alive or not.When using thread is more quick.Flow chart : +--------------+ … Read More
  • [Question 8] Hangman version2Learn something :1. If yes then draw a line next to block,otherwise draw under block.2. Using Flow Chart to design code is more convenience.Flow Chart… Read More
  • [Question 8] HangmanDescription Hangman is a popular word guessing game where the player attempts to construct a missing word by guessing one letter at a time. After a ce… Read More
  • [Question 7] Html_converterDescription :Use Python to converter the code become html format.Code :#! /usr/bin/env python# -*- coding: UTF-8 -*-# html_converter version 1.0import… Read More

0 意見:

張貼留言