OOP03_Class_Instance_Variables_Methods.py
python_old/OOP03_Class_Instance_Variables_Methods.py
class Student:
school = "Python High School" # class variable
def __init__(self, name):
self.name = name # instance/object variable
def print_name(self): # instance method
print(f"My name is {self.name}")
@classmethod # decorator
def print_school(cls): # class method
print(f"Our school is {cls.school}")
@staticmethod
def print_info(): # static method
print("This is a student class")
def __repr__(self):
return f"Student(name={self.name})"
def __str__(self):
return f"Student(name={self.name})"
def __len__(self):
return len(self.name)
if __name__ == "__main__":
student_John = Student("John")
print(student_John)
print(repr(student_John))
print(str(student_John))
print(len(student_John))
student_John.print_name()
student_John.print_school()
Student.print_info()
相關文章
01_classical_caesar_cipher.py
01_classical_caesar_cipher.py — python source code from the python old learning materials (python_old/Cryptography/01_classical_caesar_cipher.py).
閱讀文章 →02_classical_monoalphabetic.py
02_classical_monoalphabetic.py — python source code from the python old learning materials (python_old/Cryptography/02_classical_monoalphabetic.py).
閱讀文章 →03_classical_rail_fence.py
03_classical_rail_fence.py — python source code from the python old learning materials (python_old/Cryptography/03_classical_rail_fence.py).
閱讀文章 →04_frequency_analysis.py
04_frequency_analysis.py — python source code from the python old learning materials (python_old/Cryptography/04_frequency_analysis.py).
閱讀文章 →05_cryptographic_hashing.py
05_cryptographic_hashing.py — python source code from the python old learning materials (python_old/Cryptography/05_cryptographic_hashing.py).
閱讀文章 →06_password_hashing.py
06_password_hashing.py — python source code from the python old learning materials (python_old/Cryptography/06_password_hashing.py).
閱讀文章 →