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
《素描初步——静物绘制基础教程》内容简介:静物画是学习素描中重要的一部分,初学者在学习时会遇到造型不准确、画不准结构、比例
《做东:酒局里的100个生存哲学》内容简介:酒局是阴谋四伏的人性的斗争舞台,是人最高生存智慧的展示场所。《做东》是第一本最全面
计算理论是计算机科学的理论基础。《计算理论基础》(第2版)介绍了计算理论最核心、最基本的内容,包括形式语言与自动机、可计算性
《素描基础全解:石膏几何体(修订版)》内容简介:本书内容包含素描基础知识、单个静物形体与组合静物形体绘制详解三大部分。案例
《世界是設計》與構思設計本身的面向有關。在此,不把設計理解為精製、美化、裝飾。設計一字的最初意義隱含構思起草。設計首先是
《职工代表大会实务操作与法律依据》内容简介:针对当前企事业单位民主管理制度职工代表大会召开中经常遇到的问题,按照由宏观到微
智能手机故障检测与维修实战技巧全图解 本书特色本书以手机维修现场检测实操及图解的方式,系统地讲解了维修工具的使用方法、手机电路图读图技能、手机元器件故障检修的检...
瓦片颗粒和板型颗粒有什么区别?搭建墙壁时用堆叠法为什么不好?你怎样搭建乐高马赛克,怎样用不同的比例搭建?所有问题你都可以
《大学的理想》内容简介:《大学的理想》一书,精选出作者王冀生自1996年以来,公开发表的众多有关学术论文、报告、演讲和若干本有
数据库系统概念(第五版·影印版) 目录 第1章导论第1部分关系数据库第2章关系模型第3章SQL第4章高级SQL第5章其他关系语言第2部分数据库设计第6章数据库设...
Scala是一种针对JVM的通用的编程语言,用来以简明、优雅、类型安全的方式表示常见的编程模式。它无缝集成了面向对象语言和函数式
《Docker全攻略》内容简介:Docker是一个充满挑战性和趣味性的开源项目,它彻底释放了Linux虚拟化的威力,极大地缓解了云计算资源供
3DSMAX/VRAY印象效果图灯光与色彩的表现附光盘 本书特色 《3ds Max/VRay 印象效果图灯光与色彩的表现》适合有一定基础的3ds Max和VRa...
《精彩江苏·画派系列:常州画派》内容简介:常州画派由一批生活在江南文化古城常州的画家群体组成,恽寿平是常州画派开山鼻祖,以
达尔文的黑匣子:生化理论对进化论的挑战,ISBN:9787801092663,作者:(美)迈克尔·J.贝希[M.J.Behe]著;邢锡范[等]译作者简介
《空间信息网络传输协议》内容简介:本书系统、全面地介绍了空间信息网络的特点及其对传输协议造成的影响;重点介绍和讨论了空间信
《玩的就是调侃:打造你的金牌博客》按博客的主要内容,将纷繁复杂的博客群体划分为五大类,一一介绍,每章通过对该类博客总体情况
《互联网营销:理念的颠覆与蜕变》内容简介:这本书把互联网商业的新营销思维,简要地归纳为四个英文字母SURE,分别代表口碑扩散(
《一朵云推动另一朵云》内容简介:成长,永远是一个人生命中最重要的功课。本书俞敏洪对教育的反思,也是俞敏洪的率真世界观。通过
《Java技术手册(原书第7版)》内容简介:本书共分为两部分,第一部分介绍了Java开发环境、基本句法、面向对象编程、类型系统、内存