<Web Scraping with Python> Chapter 1 & 2: Your First Web Scraper & Advanced HTML Parsing BeautifulSoup Key: P5: urlib or urlib2? If you’ve used the urllib2 library in Python 2.x, you might have noticed that things have changed somewhat…
In this chapter I present classes to represent playing cards, decks of cards, and poker hands.If you don't play poker, you can read about it at http://en.wikipedia.org/wiki/Poker, but you don’t have to; I’ll tell you what you need to know for the exe…
17.1 Object-oriented featuresPython is an object-oriented programming language, which means that it provides features that support object-oriented programming.It is not easy to define object-oriented programming, but we have already seen some of its…
16.1 TimeAs 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: class Time(object): """Represents the time of day. attributes: hour, minute, second &qu…
12.1 Tuples are immutable(元组是不可变的)A tuple is a sequence of values. The values can be any type, and they are indexed by integers, so in that respect tuples are a lot like lists. The important difference is that tuples are immutable.Syntactically, a tu…
Dictionaries A dictionary is like a list, but more general. In a list, the indices have to be integers; in a dictionary they can be (almost) any type.You can think of a dictionary as a mapping between a set of indices (which are called keys) and a se…
10.1 A list is a sequenceLike a string, a list is a sequence of values. In a string, the values are characters; in a list, they can be any type. The values in a list are called elements or sometimes items.There are several ways to create a new list;…