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
从光学电报到无绳电话,我们的交流关系是怎样形成的?这就是本书所试图回答的问题。在这本书中,帕特里斯•费里奇详细描述了第一批
本书从讲解什么是数据结构开始,延伸至高级数据结构和算法分析,强调数据结构和问题求解技术。本书的目的是从抽象思维和问题求解
《PLC标准化编程原理与方法》内容简介:本书针对PLC编程工程师设计工作量大、现场调试时间长、售后服务工作量大、工作效率低的现状
本书全面而系统地介绍了安藤忠雄的作品,包括他从成名以来到现在的一些代表作以及他最新的一些作品。书中所用的图纸和资料都由安藤
CaptainRifle,grayandoldintheAlaskanSteamshipservice,hadnotlostthespiritofhisyout...
《知书达礼》内容简介:本书为《中华传统价值观丛书》中的一种,着眼于知书达礼这一重要的价值取向,编选历代关于读书治学、修身复
《行摄!肯尼亚!》内容简介:《行摄!肯尼亚!》以作者的亲历行程为主线,介绍了肯尼亚各地区的风土人情、野生动物、自然风光,并
《随波逐源》内容简介:本书是作者在追寻生命和物质本源的基础上,探寻人生意义过程中的一些认识及体会,书中汇集了作者对于人生观
《金融的逻辑(套装共2册)》内容简介:《金融的逻辑》(上、下)是陈志武教授关于金融的发展历史、演变、影响和作用的一部作品,由
科学计算自由软件SCILAB基础教程 内容简介 本书是关于科学计算自由软件SCILAB的入门教材。本书前三章分别介绍了SCILAB环境,SCILAB数据类型、运...
Recentyearshaveseenthedevelopmentofpowerfultoolsforverifyinghardwareandsoftwares...
HowtoBreakSoftwareisadeparturefromconventionaltestinginwhichtestersprepareawritt...
《地理信息技术与地理教学的整合》内容简介:本书总结了地理信息技术应用于地理教学的研究成果,从理论上探讨了地理信息技术的教学
数据库系统工程师考试大纲 本书特色 数据库系统工程师是计算机技术与软件专业技术资格(水平)考试“信息系统”类的中级资格,于2020年审定通过并于2021年使用。...
《穿透财报:发现企业的秘密》内容简介:这是一本关于中国上市公司财报分析的案例集。但是,它不同于一般的案例集。在这本案例集中
《科学新领域的探索》:美国新墨西哥州洛基山脚下的圣菲研究所离洛斯阿拉莫斯国家实验室(LANL)不远,以研究复杂系统而著称。在
Asimple,practical,andconciseguidetotimberdesignTofullyunderstandstructuraldesign...
《互联网商业的下半场》内容简介:随着人工智能和IT技术的发展,以科技为圆心、以资本为半径的互联网商业的上半场已离我们远去,以
在内容上,本书结合使用情景,全面、深入、细致地分析Android系统的源代码,涉及到Linux内核层、硬件抽象层(HAL)、运行时库层(
Excel函数与图表应用技巧500例-(附赠多媒体光盘一张) 本书特色 《Excel函数与图表应用技巧500例(附光盘实用技巧快学速查手册)》由梁为民主编,本书...