随笔分类 -  Python Learning

摘要:So far we have seen stack diagrams, which show the state of a program, and object diagrams, which show the attributes of an object and their values. T... 阅读全文
posted @ 2014-10-06 18:48 平静缓和用胸音说爱 阅读(346) 评论(0) 推荐(0)
摘要:The language feature most often associated with object-oriented programming is inheritance. Inheritance is the ability to define a new class that is a... 阅读全文
posted @ 2014-10-06 18:10 平静缓和用胸音说爱 阅读(416) 评论(0) 推荐(0)
摘要:To deal cards, we would like a method that removes a card from the deck and returns it. The list method pop provides a convenient way to do that. Sinc... 阅读全文
posted @ 2014-10-06 17:33 平静缓和用胸音说爱 阅读(267) 评论(0) 推荐(0)
摘要:Now that we have Card objects, the next step is to define a class to represent decks. Since a deck is made up cards, a natural choice is for each Deck... 阅读全文
posted @ 2014-10-06 14:17 平静缓和用胸音说爱 阅读(274) 评论(0) 推荐(0)
摘要:For built-in types, there are conditional operators (, ==, etc.) that compare values and determine when one is greater than, less than, or equal to an... 阅读全文
posted @ 2014-10-06 13:55 平静缓和用胸音说爱 阅读(186) 评论(0) 推荐(0)
摘要:In order to print Card objects in a way that people can easily read, we need a mapping from the integer codes to the corresponding ranks and suits. A ... 阅读全文
posted @ 2014-10-03 14:25 平静缓和用胸音说爱 阅读(243) 评论(0) 推荐(0)
摘要:There are fifty-two cards in a deck, each of which belongs to one of four suits and one of thirteen ranks. The suits are Spades, Hearts, Diamonds, and... 阅读全文
posted @ 2014-10-03 13:29 平静缓和用胸音说爱 阅读(195) 评论(0) 推荐(0)
摘要:Write a definition for a class named Kangaroo with the following methods:An __init__ method that initializes an attribute named pouch_contents to an e... 阅读全文
posted @ 2014-10-03 12:56 平静缓和用胸音说爱 阅读(191) 评论(0) 推荐(0)
摘要:In the previous section we added two Time objects, but you also might want to add an integer to a Time object. The following is an alternative version... 阅读全文
posted @ 2014-10-02 22:23 平静缓和用胸音说爱 阅读(206) 评论(0) 推荐(0)
摘要:By defining other special methods, you can specify the behavior of operators on user-defined types. For example, if you define add method for the Time... 阅读全文
posted @ 2014-10-02 20:52 平静缓和用胸音说爱 阅读(243) 评论(0) 推荐(0)
摘要:__str__ is a special method name, like __init__, that is supposed to return a string representation of an object.For example, here is a str method for... 阅读全文
posted @ 2014-10-02 20:23 平静缓和用胸音说爱 阅读(222) 评论(0) 推荐(0)
摘要:The init method is a special method that gets invoked when an object is instantiated. Its full name is __init__ (two underscore characters, followed b... 阅读全文
posted @ 2014-10-02 15:59 平静缓和用胸音说爱 阅读(205) 评论(0) 推荐(0)
摘要:Python is an object-oriented programing language, which means that it provides features that support object-oriented programming. It is easy to define... 阅读全文
posted @ 2014-10-02 15:27 平静缓和用胸音说爱 阅读(282) 评论(0) 推荐(0)
摘要:Sometimes it is useful for a function to modify the objects it gets as parameters. In that case, the changes are visible to the caller. increment, whi... 阅读全文
posted @ 2014-10-02 13:12 平静缓和用胸音说爱 阅读(304) 评论(0) 推荐(0)
摘要:In the next few sections, we’ll write two versions of a function called add_time, which calculates the sum of two Time objects. They demonstrate two k... 阅读全文
posted @ 2014-10-02 11:01 平静缓和用胸音说爱 阅读(190) 评论(0) 推荐(0)
摘要:As another example of a user-defined type, we’ll define a class called Time that records the time of day. The class definition looks like this: ... 阅读全文
posted @ 2014-10-01 18:00 平静缓和用胸音说爱 阅读(274) 评论(0) 推荐(0)
摘要:Aliasing can make program difficult to read because changes made in one place might have unexpected effects in another place. It is hard to keep track... 阅读全文
posted @ 2014-09-30 00:13 平静缓和用胸音说爱 阅读(294) 评论(0) 推荐(0)
摘要:We can change the state of an object by making an assignment to one of its attributes. For example, to change the size of a rectangle without changing... 阅读全文
posted @ 2014-09-29 23:17 平静缓和用胸音说爱 阅读(179) 评论(0) 推荐(0)
摘要:Sometimes it is obvious what the attributes of an object should be, but other times you have to make decisions. For examples, imagine you are designin... 阅读全文
posted @ 2014-09-25 15:47 平静缓和用胸音说爱 阅读(314) 评论(0) 推荐(0)
摘要:You can assign values to an instance using dot notation. This syntax for selecting a variable from a module, such as math.pi or string.uppercase. In t... 阅读全文
posted @ 2014-09-25 14:58 平静缓和用胸音说爱 阅读(279) 评论(0) 推荐(0)