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
CreatingBreakthroughProductsidentifieskeyfactorsassociatedwithsuccessfulinnovati...
MSC Adams多体动力学仿真基础与实例解析-(赠1DVD) 本书特色 《mscadams多体动力学仿真基础与实例解析(附光盘)/万水msc技术丛书...
《破茧成蝶2——以产品为中心的设计革命》内容简介:互联网下半场来袭,从业者需要做出怎样的变化,以应对风云突变的大环境呢?本书
《量子思维:探寻生命觉醒之旅》内容简介:本书把生命、意识乃至社会进化史当作一个觉醒过程,以东西方结合的特殊视角,采用“从顶
MoreEffectiveC++的重点包括:·经过验证的一些用来改善程序效率的方法,包括尖锐而犀利地检验C++语言特性所带来的时间和空间上的
《中国资本市场研究报告(2019)》内容简介:本研究报告是中国人民大学金融与证券研究所(Finance and Securities,FSI)所长吴晓求
《智能风控:原理、算法与工程实践》内容简介:本书以Python作为实现智能风险管理的编程语言,而我个人也十分推崇运用Python分析金
《捏什么都可爱!超实用的黏土手作笔记》内容简介:捏什么都可爱,讲解了制作黏土手工制品的基础知识,以超轻黏土为主材料,搭配树
《个性:极简庄子》内容简介:王蒙写给年轻人的中国智慧读本,凝聚数十年读书心得与人生经验,直达《庄子》精华内核。在本书中,王
《数据中台产品经理》内容简介:随着移动互联网的快速发展,“中台”纷纷在国内大小互联网企业快速落地。前有阿里云智能事业群对外
《背包为家》内容简介:本书是儿童文学著名作家张国龙新近创作的一本随笔美文集,共分为背包回家、遥想他乡、天涯情旅三卷,其中所
《2014高技术发展报告》是中国科学院面向公众、面向决策人员的系列年度报告——《高技术发展报告》的第十五本。《2014高技术发展
《从零开始学Python数据分析与挖掘》内容简介:本书以Python3版本作为数据分析与挖掘实战的应用工具,从Pyhton的基础语法开始,陆续
由鲍卫兵主编的《通信原理》由几所高校中长期从事教学实践的教师联合编写,内容全面、难度适中、分析由浅入深,论理清晰,逻辑性
《汉朝大历史》内容简介:汉朝何以成为与西罗马并立的两大帝国?汉朝的大一统局面是如何出现的?汉哀帝的断袖之癖,汉朝与四夷的战
揭开时间之谜一直是人类一个最古老的梦想。其中可想而知的是,与了解过去一切相比,人们更渴望拉开未来的帷幕。其实,对于往事的
BookDescriptionThemodernWebisawashwithdataandservicesjustwaitingtobeused,buthowd...
《Vue.js应用测试》内容简介:Vue.js创始人尤雨溪(Evan You)鼎力推荐!Vue官方测试工具作者亲笔撰写。本书是一本为Vue应用程序开
无师自通学点电脑新手学photoshop图像处理 本书特色 本书共分为12章,通过理论与实践相结合,全面、详细讲解了初识图像处理、创建与编辑选区、调整色...
Step-by-stepguiderevealsbestpracticesforenhancingWebsiteswithAjax*Astep-by-stepg...