Created
January 30, 2013 12:43
-
-
Save fmasanori/4673041 to your computer and use it in GitHub Desktop.
OOP basic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
class Pessoa(): | |
def __init__(self, nome, nascimento): | |
self.nome = nome | |
self.nascimento = nascimento | |
def idade(self): | |
delta = datetime.date.today() - self.nascimento | |
return int(delta.days/365) | |
def __str__( self ): | |
return '%s, %d anos' %(self.nome, self.idade()) | |
masanori = Pessoa('Fernando Masanori', datetime.date(1980, 9, 1)) | |
print (masanori.idade()) | |
print (masanori) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment