Classes and data types

Classes and data types

  • Dragon Boat Festival just finished dumplings blood and tears wrote this article! ! !

87- class and data type - Dragon .jpg

  • python3 unified concept of class and type is the type of class
class Foo:
    pass


obj = Foo()
print(type(obj))
<class '__main__.Foo'>
lis = [1, 2, 3]
lis2 = [4, 5, 6]
print(type(lis))
<class 'list'>
  • lis and lis2 are instantiated objects, methods and lis the append independent lis2
lis.append(7)
print(lis)
[1, 2, 3, 7]
print(lis2)
[4, 5, 6]

list.append () method principle

87- classes and data types - rocket principle .jpg

class OldboyStudent:
    school = 'oldboy'

    def __init__(self, name, age, gender):
        self.name = name
        self.age = age
        self.sex = gender

    def choose_course(self, name):
        print(f'{name} choosing course')


stu1 = OldboyStudent('nick', 18, 'male')
stu1.choose_course(1)  # OldboyStudent.choose_course(stu1, 1)
1 choosing course
OldboyStudent.choose_course(stu1, 1)
1 choosing course
lis = [1, 2, 3]  # lis = list([1,2,3])
print(type(lis))
<class 'list'>
lis.append(4)  # list.append(lis,4)
print(lis)
[1, 2, 3, 4]
list.append(lis, 5)
print(lis)
[1, 2, 3, 4, 5]

Guess you like

Origin www.cnblogs.com/nickchen121/p/10987642.html