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
软件测试方法与技术实践指南ASP.NET版 内容简介 本书以实际项目为原型、关键的理论与丰富的实践为指导,贯彻了先进的项目管理理念与全程质量管理思想。通过asp...
图像目标分割方法 本书特色 陆玲、王蕾编*的《图像目标分割方法》主要介绍图像中目标分割的几种方法及相应方法的VC6.0 程序设计,以应用实例为主线进行展开。主要...
《创业为了什么?》内容简介:本书以主播安生的视角,讲述了7个创业者的故事,并附上与创业者的对话,不仅剖析了优秀创业者的成长历
《中国经济改革与发展研究报告(2017)》内容简介:本书以“创新:引领发展的第一动力”为主题,从产业升级、全要素生产率、增长动
《MATLAB图像处理超级学习手册》内容简介:本书以MATLAB R2013a版本的功能叙述为主,由浅入深全面地讲解了MATLAB软件在图像处理方面
C++Primer中文版第4版 内容简介 作为目前业界广泛使用的编程语言,C++可谓包罗万象、博大精深。20年来,讲述C++的图书早已经汗牛充栋、层出不穷,但其...
《李叔同的佛心禅韵:花雨满天悟禅机(新版)》内容简介:无尽奇珍供世眼,一轮圆月耀天心。大师以书画名家而为出世高僧,复以翰墨
《盛开·90后新概念·花样年华书系·樱花纪》内容简介:本书系新概念作文获奖者作品精华,约32万字。本书中这些作品共分五辑,每个
TheResourceDescriptionFramework(RDF)isastructurefordescribingandinterchangingmet...
本书详细介绍了层叠样式表单的基本要素,包括CSS的基本概念、CSS属性、格式化模型以及CSS单位等。此外,对于CSS的延伸扩展部分也
《原来宋词可以这样读》内容简介:所谓词者,句有长短,然情意绵绵,翻开来,爱情、亲情、思乡情,众情毕备;王公、文人、妓女,世
Digitalobjects,intheirsimplestform,aredata.Theyarealsoanewkindofindustrialobject...
本书以通信系统及其发展为线索,系统、深入地介绍了通信技术的基本原理及其应用,着重论述了数字通信原理,但对模拟通信也进行了
《首饰设计》系统地介绍了珠宝首饰设计,其侧重点在于开拓我们的创意性思维。作者以一个西方首饰专家独特的视角和对专业领域孜孜
《揭秘Web应用程序攻击技术》适合所有热爱网络安全的人们,尤其是高等院校计算机专业的学生。同时,《揭秘Web应用程序攻击技术》
CSSMasteristailor-madeforthewebdesignerwhosreallyseriousabouttakingtheirskillsto...
《创新+法》内容简介:本书介绍内容即:创新是事物发展的不竭动力,但创新投入与产出常常不成正比,可能发生聚集效应,也可能一步为
Duringthepastdecadetherehasbeenanexplosionincomputationandinformationtechnology....
《空战百年》内容简介:这是一本从过去到未来,从技术到战术,从社会学的意涵到艺术的审美,全方位对空战进行解析的著作。从“一战
如果你可以编写出合格的代码,但是想更进一步、创作出组织良好而且易于理解的代码,并希望成为一名真正的编程专家或提高现有的职