Im really confused about Classes


Can somebody please explain to me exactly what classes are used for, why they’re used and pretty much how they work. I understand the involved code, but I don’t really understand anything else about this.


The first and foremost strength of a class is closure. A class is a self-contained function factory, where instances carry away with them unique data points and a collection of inherited methods with which to manipulate said data.

>>> class Person:
    def __init__(self, name, age): = name
        self.age = age
    def __repr__(self):
        return "Name: %s\nAge : %d" % (, self.age)

>>> me = Person("Roy", 63)
>>> me
Name: Roy
Age : 63

Granted, my instance only has the one method, but it should be clear how this plays out in the bigger picture.


Para que serve ali o %d e da onde voce tiro ele?


Desculpe, eu não entendo a sua pergunta.


Sabe ali emcima voce boto Name: %s %s= %string
e em Age = %d
%d = ?
nao sei oq significa era pra ser %int


The print format operator, % indicates an interpolated value from the tuple outside the string, also indicated by %.

>>> print "String %s, number %d, integer %i, float %f" % ("hello", 42, 42, 3.14159)
String hello, number 42, integer 42, float 3.141590

%d and %i` are the same thing.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.