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
《推开红酒的门》内容简介:葡萄酒的世界很有趣,但是初学者往往遇上麻烦:在餐厅,看着酒单上密密麻麻的字一脸懵;面对货架上琳琅
《搜索模式》内容简介:本书是信息架构领域创始人彼得·莫维里的又一力作,全书详尽剖析了10种搜索模式,告诉读者如何为不同情境设
本书是极负盛名的C语言入门经典教材,其第一版发行至今已有20年的历史。本书内容详实全面,由浅入深,示例丰富,并在每个章节后面
数据分析实战-基于EXCEL和SPSS系列工具的实践 本书特色 本书分为三大部分,*部分基础篇(第1章和第2章)主要介绍数据分析的概念、术语、方法、模型等,为后...
《超级学习(全4册)》内容简介:不断⾃我提升,需要⼀个有效的学习模型,包括知识、能力、路径等,本书提供了一系列⾏之有效的学习
《智能机器人养成记》内容简介:本书中,作者先描述了人工智能的缺陷(一个关键的缺点是:它没有具象化),然后提出了一种制造类人机
《幸福家庭成就优秀孩子》内容简介:本书从寻找幸福、正确认识婚姻与家庭以及家庭的功能入手,让读者懂得并学会用智慧去爱所爱的人
CX5576 AutoCAD2009室内装饰装潢制图 本书特色 《中文版AutoCAD2009室内装饰装潢制图》特色:详细讲解了不同功能房间的设计要素和特点.以...
本书介绍了CATIAV5CAD部分的主要模块,分6章依次介绍CATIAV5的操作入门、草图设计、零件设计、曲面造型、装配设计和工程绘图。本
《储蓄投资金融政治经济学》内容简介:在货币经济中,储蓄投资决策分离,使得统一的积累过程变成三个相互联系而又相对独立的过程,
《SilverlightASP.NET与AJAX开发实战》讨论Silverlight的部分,并没有预设读者必须具备任何背景或知识,但若能有XML的基础概念,
大数据时代计算机数据处理技术探究 内容简介 随着科技的发展,在信息化的今天,大量数据呈爆发式的增长,对这些数据的处理,是一个非常大的挑战,所以必须对数据处理技术...
《西方绘画大师经典佳作:塞尚》内容简介:印象主义画派是19世纪最重要的艺术流派之一,其将光与色彩的科学观念引入到绘画中,对当
Corporationshavefinallyrealizedthevalueofcollaborationtoolsforknowledgesharingan...
《秒懂视频号:短视频变现+直播带货+私域导流+流量运营》内容简介:本书对于短视频的下半场来说,微信视频号是普通人可以抓住的机遇
《信息时代的世界工厂》,最关切我们未来的“思想@网络.中国”丛书之一,互联网中国传媒参考书。我们生活在“信息时代”。我们的
《法律硕士(法学)联考大纲要点解析及应试策略》内容简介:对于参加法学方向的考生而言,市场上现有辅导书,无论在试题深度还是内
《巴塞尔姆的40个故事》内容简介:★有人向沉闷的世界开枪,有人写下40个故事 ★上一分钟是卓别林,下一分钟是卡夫卡 ★所有正能量
《民国大人物》内容简介:《民国大人物》是《民国大人物》第一部,讲述的是民国时期影响历史进程的大人物的人生浮沉。所写人物囊括
机器视觉算法与应用 本书特色 详述了机器视觉系统的各个组成部分、部件选择和设计要点详述了各种处理算法的原理、特点、适用性、实现及优化方法针对不同行业和应用领域剖...