1901030012-MIT-自学 lecture8

学员信息

  • 学号: 1901030012
  • 学习内容: MIT第8课视频文稿p11-13
  • 学习用时: 20min Notes no.: Day39

学习笔记

  1. type vs. class
    If we look at coordinate as a class, if we print what coordinate is, coordinate is a class, right?
    So this is what Python tells us, if we print coordinate, it’s a class named coordinate.
    And if we print the type of a coordinate, well that’s just going to be a type. So class is going to be a type. [why?]
    So you’re defining the type of an object. If you’d like to figure out whether a particular object is an instance of a particular class, you use this special function called isinstance. So if you print is instance C comma coordinate, this is going to print true because C is an object that is of type coordinate.

    This does not make sense to me:
    1
    2
    3
    4
    5
    6
    7
    8
    print(Coordinate)
    <class __main__.Coordinae>
    print(type(Coordinate))
    <type 'type'>

    use isinstance() to check if an object is a Coordinate
    print(isinstance(c, Coordinate))
    True
  2. The computer only do what you tell it how to, and Python too
    If you have not implemented this method and you try to add two objects of type coordinate, you’re going to get an error because Python doesn’t actually know right off the bat how to add two coordinate objects, right? You have to tell it how to do that. And you tell it how to do that
    by implementing this special method. Same with subtract. Same with equals.
    |SPECIAL OPERATORS| |

–|–|
defined | meaning
add(self, other) | self + other
sub(self, other) | self - other
eq(self, other) | self == other
lt(self, other) | self < other
len(self) | len(self)
str(self) | print(self)

… and others, do whatever you’d like to do. And then you
document what you’ve decided.

  1. 相信自己的源头–自己的行动
    如果我没有行动,那么还是不信点滴,认为一点一滴没有那么重要,那么还是回到自己的定义里再审视,有部分没有想明白。点滴是什么?点滴是构筑希望的点点滴滴。所以,自检机制很重要。
    1
    2
    3
    4
    def self_move(something)
    if practice(something) == False
    return None
    self_move(MIT_record)