







































Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!








































Last updated on 28/07/2020 09:
OBJECT ORIENTED PROGRAMMING
1. Title
https://docs.python.org/3/tutorial/classes.html Object Oriented Programming
1. Title
Classes and instances
1. Title
Class definition
1. Title
Basic instantiation class MyClass: """A simple example class""" def f(self): return 'hello world' x = MyClass() x.f()
1. Title
Instantiation with init (constructor) class Complex: def init(self, realpart, imagpart): self.r = realpart self.i = imagpart x = Complex(3.0, - 4.5) print(x.r, x.i)
1. Title
Instantiation with init (constructor) class Complex: def init(self, realpart, imagpart): self.r = realpart self.i = imagpart x = Complex(3.0, - 4.5) print(x.r, x.i)
1. Title
Accessing attributes x = Complex(3.0, - 4.5) x.i = 5.
1. Title
Methods, and self
1. Title
Dogs that play tricks
1. Simple example Title class Dog: def init(self, name): self.name = name self.tricks = [] # creates a new empty list for each dog def add_trick(self, trick): self.tricks.append(trick) d = Dog( 'Fido' ) e = Dog( 'Buddy' ) d.add_trick( 'roll over' ) e.add_trick( 'play dead' ) print(d.tricks)
print(e.tricks)
1. Title
Vehicle Routing
1. Title