Contenido del Curso
Object-Oriented Programming in Python
Object-Oriented Programming in Python
Implementation
Code
We start to fill the Cat
class:
- An attribute
name
with the predefined value'Kitty'
; - A method
say_meow()
.
We create an object cat
and call the say_meow()
method.
Note
- Each method obligatory contains
self
- a reference to the current object; - To call the method of the object, write
Object.Method()
.
Tarea
- Add the
sleep
method. - The
sleep
method prints a message. - Instantiate an object using the
cat
variable.
Tarea
- Add the
sleep
method. - The
sleep
method prints a message. - Instantiate an object using the
cat
variable.
¿Todo estuvo claro?
Implementation
Code
We start to fill the Cat
class:
- An attribute
name
with the predefined value'Kitty'
; - A method
say_meow()
.
We create an object cat
and call the say_meow()
method.
Note
- Each method obligatory contains
self
- a reference to the current object; - To call the method of the object, write
Object.Method()
.
Tarea
- Add the
sleep
method. - The
sleep
method prints a message. - Instantiate an object using the
cat
variable.
Tarea
- Add the
sleep
method. - The
sleep
method prints a message. - Instantiate an object using the
cat
variable.
¿Todo estuvo claro?
Implementation
Code
We start to fill the Cat
class:
- An attribute
name
with the predefined value'Kitty'
; - A method
say_meow()
.
We create an object cat
and call the say_meow()
method.
Note
- Each method obligatory contains
self
- a reference to the current object; - To call the method of the object, write
Object.Method()
.
Tarea
- Add the
sleep
method. - The
sleep
method prints a message. - Instantiate an object using the
cat
variable.
Tarea
- Add the
sleep
method. - The
sleep
method prints a message. - Instantiate an object using the
cat
variable.
¿Todo estuvo claro?
Code
We start to fill the Cat
class:
- An attribute
name
with the predefined value'Kitty'
; - A method
say_meow()
.
We create an object cat
and call the say_meow()
method.
Note
- Each method obligatory contains
self
- a reference to the current object; - To call the method of the object, write
Object.Method()
.
Tarea
- Add the
sleep
method. - The
sleep
method prints a message. - Instantiate an object using the
cat
variable.