In [1]:
class Galleta:
pass
una_galleta = Galleta()
In [2]:
una_galleta.sabor = "Salado"
In [3]:
una_galleta.color = "Marrón"
In [5]:
print("El sabor de esta galleta es",una_galleta.sabor)
In [7]:
class Galleta:
chocolate = False
g = Galleta()
g.chocolate
Out[7]:
In [8]:
g.chocolate = True
g.chocolate
Out[8]:
In [9]:
class Galleta():
chocolate = False
def __init__(self):
print("Se acaba de crear una galleta.")
g = Galleta()
In [14]:
class Galleta():
chocolate = False
def __init__(self):
print("Se acaba de crear una galleta.")
def chocolatear(self):
self.chocolate = True
def tiene_chocolate(self):
if (self.chocolate):
print("Soy una galleta chocolateada :-D")
else:
print("Soy una galleta sin chocolate :-(")
g = Galleta()
g.tiene_chocolate()
g.chocolatear()
g.tiene_chocolate()
In [21]:
class Galleta():
chocolate = False
def __init__(self, sabor, forma):
self.sabor = sabor
self.forma = forma
print("Se acaba de crear una galleta {} y {}".format(sabor,forma))
def chocolatear(self):
self.chocolate = True
def tiene_chocolate(self):
if (self.chocolate):
print("Soy una galleta chocolateada :-D")
else:
print("Soy una galleta sin chocolate :-(")
In [19]:
g = Galleta("salada","cuadrada")
In [20]:
g = Galleta()
In [24]:
class Galleta():
chocolate = False
def __init__(self, sabor=None, forma=None):
self.sabor = sabor
self.forma = forma
if sabor is not None and forma is not None:
print("Se acaba de crear una galleta {} y {}".format(sabor,forma))
def chocolatear(self):
self.chocolate = True
def tiene_chocolate(self):
if (self.chocolate):
print("Soy una galleta chocolateada :-D")
else:
print("Soy una galleta sin chocolate :-(")
In [26]:
g = Galleta("salada","cuadrada")