User Tools

Site Tools


python:about_python:about_python_iii

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
python:about_python:about_python_iii [2013/08/03 05:02] – [Python objects] mithatpython:about_python:about_python_iii [2017/12/06 01:57] (current) mithat
Line 33: Line 33:
  
 In computing, we call objects that have been created from classes **instances**. Thus Jimmy's phone is an instance of a Nokia N8, Angie's phone is an instance of an iPhone 4, and Sally's is another instance of an iPhone 4. In computing, we call objects that have been created from classes **instances**. Thus Jimmy's phone is an instance of a Nokia N8, Angie's phone is an instance of an iPhone 4, and Sally's is another instance of an iPhone 4.
- 
-Python uses class-based object orientation. 
  
 === Prototype-based object orientation === === Prototype-based object orientation ===
  
-There is another kind of object orientation called **prototype-based object orientation** or **prototype-based programming**. This is the kind of object-orientation used in JavaScript and some other languages. I will leave it you to get your Google on and learn more about prototype-based object orientation.+There is another kind of object orientation called **prototype-based object orientation** or **prototype-based programming**. This is the kind of object-orientation used in JavaScript and some other languages.((C++, Java, C#, and PHP support only class-based object orientation; JavaScript and Ruby are inherently prototype-based; Objective-C is class-based but lets you do prototypal-based programming.)) I will leave it you to get your Google on and learn more about prototype-based object orientation.
  
-You can do prototype-based programming with Python as well, but we'll stick to class-based programming for the rest of this.+==== Python objects ====
  
-==== Python objects ====+Python is inherently class-based, but it's not hard to do prototypal-style programming as well. We will stick to class-based object orientation here.
  
 We will next define a class in Python and instantiate and use some objects. We will next define a class in Python and instantiate and use some objects.
Line 163: Line 161:
 class ClickerCounter(): class ClickerCounter():
     def __init__(self):  # constructor     def __init__(self):  # constructor
-        count = 0+        self.count = 0
          
     def get_count(self):  # accessor for count     def get_count(self):  # accessor for count
Line 181: Line 179:
 class ClickerCounter(): class ClickerCounter():
     def __init__(self):  # constructor     def __init__(self):  # constructor
-        count = 0+        self.count = 0
          
     def set_count(self, count):  # mutator for count     def set_count(self, count):  # mutator for count
python/about_python/about_python_iii.1375506161.txt.gz · Last modified: 2013/08/03 05:02 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki