Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (1)

Powered by Vanilla. Made with Bootstrap.
OOP example 3
  • chroniccommand
    Posts: 1,389
    So this is my third simple OOP example. Since I'm learning as I go I figured I'd share some knowledge. Here, we involve creating a new object without first defining it in __init__

    #!/usr/bin/env python
    '''
    Python Object Oriented Programming example number three
    We will be using a simple person example
    '''

    class HumanPerson(object):
    def __init__(self, name, age, sex):
    self.name = name
    self.age = age
    self.sex = sex
    def PrintHuman(self):
    print(\"Name: \" + self.name)
    print(\"Age: \" + self.age)
    print(\"Sex: \" + self.sex)
    print(\"Status: \" + self.status)
    name = raw_input(\"Enter your name: \")
    age = raw_input(\"Enter your age: \")
    sex = raw_input(\"Sex: \")
    status = raw_input(\"Status(EG happy/sad): \")
    humaninit = HumanPerson(name, age, sex)
    humaninit.status = status #Notice how we don't define this in __init__
    humaninit.PrintHuman()