-
-
Save DugalMcCrow/ff86af1199bade234834a024b4d3ae13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> # Use a custom class | |
>>> class Student0: | |
... def __init__(self, name, gender, student_id): | |
... self.name = name | |
... self.gender = gender | |
... self.student_id = student_id | |
... | |
>>> s0 = Student0('John', 'M', 2020001) | |
>>> f"Name: {s0.name}; Gender: {s0.gender}; ID #: {s0.student_id}" | |
'Name: John; Gender: M; ID #: 2020001' | |
>>> | |
>>> # Use the namedtuple | |
>>> from collections import namedtuple | |
>>> Student1 = namedtuple("Student1", ["name", "gender", "student_id"]) | |
>>> s1 = Student1('Jennifer', 'F', 2020002) | |
>>> f"Name: {s1.name}; Gender: {s1.gender}; ID #: {s1.student_id}" | |
'Name: Jennifer; Gender: F; ID #: 2020002' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment