Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # se define la clase
- class Student:
- # en este caso no hay parametro 'self', la palabra en si misma es uan convencion
- # pero puede usarse otra cosa como 'student'
- # se definen los atributos
- def __init__(student, name, subjects):
- if not isinstance(name, str):
- raise TypeError("name must be a string")
- elif not isinstance(subjects, list):
- raise TypeError("subjects must be a list")
- student.name = name
- student.subjects = subjects
- # metodos
- def print_info(student):
- print(f"Nombre: {student.name}")
- print(f"Materias: {student.subjects}")
- # end class
- # Instancias
- alumno_ana = Student("ana", ["biologia","matematica", "historia"])
- alumno_pablo = Student("pablo", ["biologia","ingles", "geografia"])
- # llamdado a los metodos
- alumno_ana.print_info()
- alumno_pablo.print_info()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement