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
曼纽尔·卡斯特是闻名世界的社会科学家,《网络社会-跨文化的视角》是他主编的探讨网络社会在不同文化和制度中的模式和动态的论
《中国海洋油气开发装备研发史》内容简介:本书是“中国船舶研发史”丛书之一,主要介绍了我国典型海洋油气开发装备的研发背景、设
《军事政治学研究(2015年第2辑/总第10辑)》内容简介:《军事政治学研究》是由中国人民解放军南京政治学院军事政治学研究中心创办
《中国式价值投资(修订版)》内容简介:2009年6月,李驰在北京见到索罗斯,提出了一个思索很久的问题:能不能既做巴菲特,又做索罗
PDA软件市场不但巨大,而且持续成长。五年之内,全世界将有大量人口使用精明时髦,可上网的移动电话。每个家庭都有一台PC?!或许
『書‧手作:山崎曜的製本書』超乎興趣的復古工藝之作、一本大人風味的手工書13種製書技法.25件佳作實做詳解.5件職人創作欣賞※
高效商业分析-Excel建模与决策 本书特色 本书基于excel这一*常见的工具介绍商业分析在业务中的应用,帮助我们做出更优异的商业决策。书中不但提供了商业分析...
「平面設計是帶給人夢想的幸福工作。從事平面設計,除了需要一點幽默和感性之外,擁有平面設計的基本知識更是必備條件。」本書收
《高绩效HR必备图表范例》内容简介:当今人力资源管理领域面临诸多新问题、新环境、新理念、新技术,各种名类繁杂的图书也大量涌现
《基于4G系统的移动服务技术》介绍了构建一种前所未有的新的业务提供的方法学、解决方案以及富有前景的深入视角。通过对未来网络
"HeadFirstObjectOrientedAnalysisandDesign"isarefreshinglookatsubjectofOOAD.Whats...
葛列众,男,1956年出生,工学博士,浙江理工大学教授,博士生导师,心理研究所所长。现任中国心理学会工业心理学专业委员会副主
《奇点艺术》内容简介:艺术和科技领域的划时代作品,世界艺术专家、“奇点艺术”理念提出者对未来艺术的蜕变进行可靠的演绎和预测
RAW格式数码照片处理完全解析-(附光盘) 本书特色 raw格式是目前所有数码摄影人士都非常喜爱的影像格式,但由于raw格式图片在转换过程中步骤繁多,让许多影友...
本书从跨学科的视角探索了知识可视化的历史进程及其最新进展。从无形学院和库恩竞争范式,到运用可视化技术绘制知识结构图谱,再
《数字档案资源社会化开发》内容简介:档案信息资源开发是对档案内容的一种再现叙事。长期以来,这种再现叙事的主体主要是保管档案
《增值税实务操作与发票管理》内容简介:本书内容按增值税要素、征收管理、发票管理进行分类,突出时效性、延续性、准确性与工具性
本书是一本与众不同的Java入门好书。作者以独特的视角,向Java初学者讲述了如何才能真正理解和掌握Java语言。本书充分考虑了初学
《承包地“三权分置”的法律表达与实效考察》内容简介:2018年中央一号文件着重提出深化农村土地制度改革,其中包括进一步完善农村
本教材介绍了计算机系统中的一个重要系统软件——操作系统(0S)。全书共分10章,第l章介绍OS的发展过程、基本特征、功能以及OS的结