Pacific-Design.com

    
Home Index

1. Python

+ 01 String

+ 02 Dictionary

+ 03 Array

+ 04 List

+ 05 Tupple

+ 06 Regex

+ 07 File

+ Arguments

+ Binary Tree

+ Calendar

+ Date

+ Debug

+ Exception

+ JSON

+ MySQL

+ NLP

+ Python 3

+ Thread

+ UTC Local Time

+ Validate IP Address

+ Vim

+ YAML

Python /

Python - Class Instantiation

#!/usr/bin/python
#------------------------------------------------#
class Dog:

    # class variable shared by all instances
    kind = 'Canine'

    # instance variable unique to each instance
    def __init__(self, name):
        self.name = name
        self.tricks = []

    def add_trick(self, trick):
        self.tricks.append(trick)

#------------------------------------------------#
d = Dog('Fido')
e = Dog('Buddy')

d.add_trick('roll over')
e.add_trick('play dead')

print(d.kind, d.name, d.tricks)
print(d.kind, e.name, e.tricks

Output

('Canine', 'Fido', ['roll over']) ('Canine', 'Buddy', ['play dead'])


Environment Variables

export PYTHONDONTWRITEBYTECODE

Install Requirements

$ pip install -r requirements.txt

References: