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
ThelargestgroupwithanunsatisfieddemandforagoodbookonHTTPistheworldwidegroupofWeb...
《财经写作》内容简介:本书融入了应用写作“国家级精品资源共享课程 ”建设的探索成果,注重学生写作思维的训练和培养,以“公文正
《淘宝网店深度SEO优化技术揭秘:网店流量高效转化》内容简介:淘宝搜索流量,尤其是自然搜索流量是一块大蛋糕!但是淘宝的搜索规则
你也能拍电影 内容简介 20世纪80年代以来,由电影摄影机发展而来的家庭磁带摄像机已经可以让人们随意地带到家庭、公园和街头,把这个世界的五彩缤纷留在能够重复的影...
《寂静狂欢 哥特式黑白插画绘制教程》内容简介:我们熟悉的很多插画、漫画作品中都有一些华丽、繁复、色调极暗的元素,它们也经常出
在内容上,本书结合使用情景,全面、深入、细致地分析Android系统的源代码,涉及到Linux内核层、硬件抽象层(HAL)、运行时库层(
《中国梦实现的根本法保障》内容简介:宪法序言申明的建设富强、民主、文明的社会主义国家是经济、政治、社会、文化与生态文明五位
AutoCAD2009中文版高级简明教程 内容简介 《Auto CAD 高级简明教程(2009中文版)》共分为7章,主要阐述AutoCAD的界面、绘图环境的设置...
《20世纪英国女作家研究》内容简介:英国女作家的小说创作是世界文学史上辉煌的一页,本书聚焦20世纪英国有影响的女作家及其作品,
《激活免疫力》内容简介:本书作者倡导“知行合一”的健康生活方式,坚持2800天亲自实践“早睡早起+合理饮食+科学运动”的健康生活
数字逻辑基础与Verilog设计(原书第2版)(附光盘) 内容简介 本书系统介绍数字逻辑基本概念与实际应用。主要内容包括:逻辑电路、组合逻辑、算术运算电路、存储...
《微信营销与运营一册通》内容简介:《微信营销与运营一册通》深入介绍了当今最为火热的话题——微信营销,内容全面、系统和深入。
《围棋死活二选一从入门到精通(级位篇)》内容简介:本书是由少儿围棋教育专家、职业五段棋手赵守洵专为围棋初学者创作。本书按照
《大数据区块链金融:贵阳的实践与思考》内容简介:《大数据区块链金融》一书从理论支撑、政策支持、学术研究、区块链联盟组织、区
《Arduino开发实战指南:智能家居卷》内容简介:智能家居,又称智能住宅,在国外常用Smart Home表示。通俗来说,智能家居是将灯光、
《视听媒体虚拟现实内容创作研究》内容简介:本书主要研究视听媒体虚拟现实(VR)作品内容的创作理念、创作方法和艺术规律,主要的研
《互联网企业安全高级指南》内容简介:本书由业内多位顶级安全专家亲力打造,分享了他们十多年的安全行业经验。从技术到管理,从生
《保护眼睛大作战》内容简介:陶勇医生爱眼护眼科普漫画!亲子共读!眼科普+近视矫正+常见病预防,30节爱眼护眼科普知识课,200多个
巴黎创意人的家是什么样的呢?来,一起到他们家里去看一下吧!他们钟爱手工原创,珍惜旧物,喜欢到跳蚤市场和古董市场寻找自己喜
内容介绍:文字在浩涉的文明岁月中幻化出千姿百态,于是,才会有这本文字美丽的书。从书中,也许你可读出一部中国文字美丽的历史