GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — learn-python/src/classes/test_class_definition.py at master · devarajthiyam/learn-python Expand file tree/ Copy pathtest_class_definition.pyMore file actions 46 lines (34 loc) · 1.9 KB / Copy pathtest_class_definition.pyFile metadata and controls46 lines (34 loc) · 1.9 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 """Class Definition Syntax. @see: https://docs.python.org/3/tutorial/classes.html Python is an object oriented programming language. Almost everything in Python is an object, with its properties and methods. A Class is like an object constructor, or a "blueprint" for creating objects. """ def test_class_definition(): """Class definition.""" # Class definitions, like function definitions (def statements) must be executed before they # have any effect. (You could conceivably place a class definition in a branch of an if # statement, or inside a function.) class GreetingClass: """Example of the class definition This class contains two public methods and doesn't contain constructor. """ name = 'user' def say_hello(self): """Class method.""" # The self parameter is a reference to the class itself, and is used to access variables # that belongs to the class. It does not have to be named self , you can call it # whatever you like, but it has to be the first parameter of any function in the class. return 'Hello ' + self.name def say_goodbye(self): """Class method.""" return 'Goodbye ' + self.name # When a class definition is entered, a new namespace is created, and used as the local scope — # thus, all assignments to local variables go into this new namespace. In particular, function # definitions bind the name of the new function here. # Class instantiation uses function notation. Just pretend that the class object is a # parameterless function that returns a new instance of the class. For example the following # code will creates a new instance of the class and assigns this object to the local variable. greeter = GreetingClass() assert greeter.say_hello() == 'Hello user' assert greeter.say_goodbye() == 'Goodbye user' |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |