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
《Effective C#(原书第3版)》内容简介:在本书中,世界知名的.NET专家Bill Wagner先生给出了50条建议,告诉你怎样充分利用C#6.0所
《高效能团队模式》内容简介:高效能软件开发团队是任何组织能够持续交付价值的关键。本书主要介绍了高效能团队模式——团队拓扑,
《大宋侃史官》内容简介:这是一本有灵魂、有内容、有猛料的宋朝历史,那些陷落在历史深处的人物在作者笔下的这一刻,不再是一个个
《淘宝网店金牌客服实战》内容简介:如果说电子商务是不断前行着的列车,那么客服就是推动着列车前进的动力源。本书针对客服工作的
《深入实践DDD》内容简介:本书是拥有二十年商业软件开发经验及十年技术管理经验的资深技术专家呕心沥血之作,也是目前市场上少有的
《工艺之道》内容简介:《工艺之道》是柳宗悦最早的关于工艺性质的论文集。在本书中,他一反潮流地引导大众关注日常器物的健康之美
《电商密码》内容简介:本书以真实的跨境电商平台全案为实践基础,结合现今电商行业的特点和需求,从电商平台运营者的角度对电商运
压缩感知理论的工程应用方法 内容简介 在传输带宽有限和数据量激增的数字化时代,压缩感知理论为低速有效获取信息提供了一种新的思路,成为近十年来信号信息处理领域中一...
《设计人生:罗启妍自传》内容简介:本书是出身香港、名扬世界的珠宝设计师、跨文化学者罗启妍的自传。罗启妍出生于富裕之家,家道
TheinternationalsuccessstoryofAntwerpfashionTheSix(WalterVanBeirendonck,AnnDemeu...
北欧文化有种很特殊的味道。美国洛杉矶艺术设计学院终身教授王受之用独特的见解和宽阔的视野角度、深入浅出的笔触,将北欧本身的
WhatsInside*HowRubyandRailswork,separatelyandtogether*ExtensiveRubylanguagetutor...
《C++程序设计习题与实验指导》内容简介:本书是C++程序设计语言的参考书,章节和内容编排与《C++程序设计基础教程》配套,主要包括
《宋词背后那些有趣的灵魂》内容简介:《宋词背后那些有趣的灵魂》是一本透过词人人生来品读古典诗词之美的书,囊括了十位宋代优秀
数字摄影教程 本书特色 《新世纪高等学校摄影及相关专业通用教材:数字摄影教程》作者将与青年学生们一起共同讨论数字摄影的基本知识,并探索数字摄影的奥秘。《新世纪高...
书分三部分,一是知识,是那些问而不详则枉称字型设计师的事情;二是方法论,工作室看待问题解决问题的方式;三是成功的商业委托
《行成于思:王志纲中国走势思考录》内容简介:“行成于思毁于随”。从进入中南海汇报的新华社资深记者,转变为顶尖战略咨询机构智
《给孩子讲历史》内容简介:本书一是丰富孩子的知识。历史是一个知识的宝藏,文学、政治、科学等人类所有的文明成果尽在其中,通过
ForanyonelearningtheSchemeprogramminglanguage,thesecondeditionofSimplyScheme:Int...
《在人间》内容简介:1906年,高尔基对一位知名出版人说:“我有许多写作计划,而且正在考虑写自传。”此后,他多次表示想写自传。