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
Withover250,000appstochoosefrominApplesAppStore,youcanmakeyouriPhoneoriPodTouchd...
《私人财富保护、传承与工具》内容简介:企业、家族、婚姻等多方面的真实案例,多种财富管理工具,深入介绍财富规划方案及风险。这
《黑客攻防入门(畅销升级版)》内容简介:《黑客攻防入门(畅销升级版)》从黑客新手的需要和学习习惯出发,详细介绍了黑客基础知
基于光纤技术的电信网络已经成为最主要的信息传输系统,无论是在陆地还是海底,已经形成了拥有巨大传输容量的光纤链路。各种不同
《唐诗分类品赏》内容简介:古典诗词鉴赏名家李元洛先生以今人视角依不同题材精选唐诗三百余首,分为自然、社会、人生与艺术四大篇
《神经网络结构优化方法及应用》从RBF网络训练算法、结构分解、结构优化、样本选取等几方面人手,分析了提高神经网络泛化能力和收
《基于神经网络的智能诊断》共8篇,内容涉及神经网络智能诊断的产生、发展、现状与动向,复杂系统智能诊断问题的概念和策略;基于
JakartaTomcat是世界上使用最广的Javaservlet与JSP平台。除了作为Sun公司servlet及JSP规格的参考实现之外,在几十万个网站中也占
《音乐笔记》内容简介:本书由三个部分组成,第一部分谈音乐欣赏,面对浩如烟海音乐世界,作者选择曾经感动自己的曲目和音乐家,娓
欢迎您选择一种更高效的学习HTML和CSS的方式。不管您设计和建立新网站,还是想更好地控制现有网站,都可以在《HTML&CSS设计与构建
Flash二维动画制作基础教程 本书特色 本书是中等职业教育电子信息类专业“双证课程”培养方案配套教材,同时也是“CEAC国家信息化计算机教育认证”的指定教材,...
《中国哲学创新方法论研究》内容简介:中国哲学学科自20世纪初依西方哲学范式建成以来,始终面临着方法论的困境,无论是在概念创造
《万物大历史·科学和技术是怎么发展而来的》内容简介:"大历史”概念由美国知名历史学家大卫·克里斯蒂安提出,后经比尔·盖茨大力
《移动基站设备与维护》全面、系统地阐述了现代移动基站的基本原理、基本技术和当今广泛使用的各类设备及维护技术规范,较充分地
《指尖上的会计》内容简介:学会计并不难,难的是“学得开心,用得顺手”。那么,面对那些晦涩难懂的会计术语以及财税处理工作,如
从新手到高手WPS Office办公应用从新手到高手 本书特色 本书主要讲解WPS Office 2019的三个主要组件WPS文字、WPS表格以及WPS演示在办...
HTML是网页制作的基础语言,是每个网页制作者必须掌握的内容。XHTML1.0是一种在HTML4.0基础上优化和改进的新语言,是基于XML的应
《研究型大学助力乡村振兴》内容简介:本书深入福建省浦城县农业管理部门、企业和农户,从区域发展实践出发,探讨产业发展的理论和
《一目了然Web软件显性设计之路》通过深入浅出地讲解与丰富的实际案例,帮助读者理解、掌握显性设计的精髓,可轻松熟练地设计出简
《英国陶艺设计基础教程》是一本陶艺设计的完全指导手册,融合了理论、实践、技术三方面的重点,你可以通过《英国陶艺设计基础教