[美] Bill Lubanovic《Introducing Python》

[美] Bill Lubanovic《Introducing Python》

作者:[美] Bill Lubanovic

出版社:O'Reilly Media, Inc.

出版年:2014-11-7

评分:7.2

ISBN:9781449359362

所属分类:网络科技

书刊介绍

内容简介

This book will introduce you to the Python programming language. It’s aimed at beginning

programmers, but even if you’ve written programs before and just want to add

Python to your list of languages, Introducing Python will get you started.

It’s an unhurried introduction, taking small steps from the basics to more involved and

varied topics. I mix cookbook and tutorial styles to explain new terms and ideas, but

not too many at once. Real Python code is included early and often.

Even though this is an introduction, I include some topics that might seem advanced,

such as NoSQL databases and message-passing libraries. I chose these because they can

solve some problems better than standard solutions. You’ll download and install external

Python packages, which is good to know when the “batteries included” with Python

don’t fit your application. And it’s fun to try something new.

I also include some examples of what not to do, especially if you’ve programmed in other

languages and try to adapt those styles to Python. And I won’t pretend that Python is

perfect; I’ll show you what to avoid.

作品目录

1. A Taste of Py. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Python in the Real World 5

Python versus Language X 6

So, Why Python? 9

When Not to Use Python 9

Python 2 versus Python 3 10

Installing Python 10

Running Python 11

Using the Interactive Interpreter 11

Use Python Files 12

What’s Next? 13

Your Moment of Zen 13

Things to Do 14

2. Py Ingredients: Numbers, Strings, and Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

Variables, Names, and Objects 15

Numbers 19

Integers 19

Precedence 23

Bases 24

Type Conversions 25

How Big Is an int? 26

Floats 27

Math Functions 27

Strings 27

Create with Quotes 28

Convert Data Types by Using str() 30

Escape with 30

Combine with + 31

Duplicate with * 32

Extract a Character with [] 32

Slice with [ start : end : step ] 33

Get Length with len() 35

Split with split() 35

Combine with join() 36

Playing with Strings 36

Case and Alignment 37

Substitute with replace() 38

More String Things 39

Things to Do 39

3. Py Filling: Lists, Tuples, Dictionaries, and Sets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Lists and Tuples 41

Lists 42

Create with [] or list() 42

Convert Other Data Types to Lists with list() 43

Get an Item by Using [ offset ] 43

Lists of Lists 44

Change an Item by [ offset ] 45

Get a Slice to Extract Items by Offset Range 45

Add an Item to the End with append() 46

Combine Lists by Using extend() or += 46

Add an Item by Offset with insert() 46

Delete an Item by Offset with del 47

Delete an Item by Value with remove() 47

Get an Item by Offset and Delete It by Using pop() 47

Find an Item’s Offset by Value with index() 48

Test for a Value with in 48

Count Occurrences of a Value by Using count() 49

Convert to a String with join() 49

Reorder Items with sort() 49

Get Length by Using len() 50

Assign with =, Copy with copy() 50

Tuples 52

Create a Tuple by Using () 52

Tuples versus Lists 53

Dictionaries 53

Create with {} 54

Convert by Using dict() 5

相关推荐

微信二维码