This file contains hidden or 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
| from abc import ABC, abstractmethod | |
| class Animal(ABC): | |
| @abstractmethod | |
| def move(self): | |
| pass | |
| a = Animal() | |
| # TypeError: Can't instantiate abstract class Animal with abstract methods move | |
This file contains hidden or 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
| class Student: | |
| def __init__(self, first_name, last_name): | |
| self.first_name = first_name | |
| self.last_name = last_name | |
| self.nickname = None | |
| def set_nickname(self, name): | |
| self.nickname = name |
This file contains hidden or 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
| class Student: | |
| def __init__(self, first_name, last_name): | |
| self.first_name = first_name | |
| self.last_name = last_name | |
| self.nickname = None | |
| def set_nickname(self, name): | |
| self.nickname = name | |
| @classmethod # get_from_string is a class method |
This file contains hidden or 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
| class Student: | |
| def __init__(self, first_name, last_name): | |
| self.first_name = first_name | |
| self.last_name = last_name | |
| self.nickname = None | |
| def set_nickname(self, name): | |
| self.nickname = name | |
| @classmethod |
This file contains hidden or 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
| class Student: | |
| def __init__(self, first_name, last_name): | |
| self.first_name = first_name | |
| self.last_name = last_name | |
| self.nickname = None | |
| def set_nickname(self, name): | |
| self.nickname = name | |
| @classmethod |
This file contains hidden or 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
| class Student: | |
| def __init__(self, first_name, last_name): | |
| self.first_name = first_name | |
| self.last_name = last_name | |
| @classmethod | |
| def get_from_string(cls, name_string: str): | |
| first_name, last_name = name_string.split() | |
| return Student(first_name, last_name) |
This file contains hidden or 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
| class Student: | |
| def __init__(self, first_name, last_name): | |
| self.first_name = first_name | |
| self.last_name = last_name | |
| @classmethod | |
| def get_from_string(cls, name_string: str): | |
| first_name, last_name = name_string.split() | |
| return Student(first_name, last_name) |
This file contains hidden or 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
| class Student: | |
| def __init__(self, first_name, last_name): | |
| self.first_name = first_name | |
| self.last_name = last_name | |
| @classmethod | |
| def get_from_string(cls, name_string: str): | |
| first_name, last_name = name_string.split() | |
| return cls(first_name, last_name) # CHANGED HERE |
This file contains hidden or 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
| class Student: | |
| def __init__(self, first_name, last_name): | |
| self.first_name = first_name | |
| self.last_name = last_name | |
| @classmethod | |
| def get_from_string(cls, name_string: str): | |
| first_name, last_name = name_string.split() | |
| if Student.validate_name(first_name) and Student.validate_name(last_name): | |
| return cls(first_name, last_name) |
This file contains hidden or 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
| my_list = [1, 2, 3, 4, 5] | |
| print(type(my_list)) | |
| # <class 'list'> | |
| my_list_iterator = iter(my_list) | |
| print(type(my_list_iterator)) | |
| # <class 'list_iterator'> |