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
《家国情怀 知行合一》内容简介:郑杭生先生作为改革开放后中国社会学重建的重要领导人和新时期中国社会学理论的重要开拓者,不仅为
要成功,更重要的是必須了解材料特性與其搭配的加工方式,最後才完成這個超暢銷文創商品。當你的創意被綁架,只能用手邊現有的材
《4D打印:改变未来商业生态》内容简介:相较于3D打印的蔚然成风,横空出世的4D虽说还有点显得冷清,却给人们打开了一扇更为广阔的
《神经网络权值直接确定法》提出了一种神经网络权值直接确定的方法。不同于传统的神经网络迭代学习思想,新方法可以一步直接计算
Therevisededitioncontainsanewchapterwhichprovidesanelegantdescriptionofthesemant...
Ajax将静态Web页面转变为充满交互的应用。现在您不需要牺牲Web应用程序部署的简单性,就可以将“胖”客户端应用程序部署到客户端
《乐迷闲话》内容简介:《乐迷闲话》作为辛丰年的第一本音乐随笔著作,曾经启蒙了一代西方古典音乐乐迷。虽是“闲话”,其实“有根
本书从系统观的角度深入探讨可持续问题、框架和策略。全书共5部分19章,分别从降低、重复使用、循环利用、恢复和过程五大方面介绍
《我们都一样,年轻又彷徨》内容简介:★青年作家苑子文&苑子豪暖心励志代表作,全新升级典藏版正式上市。★关于勇气、成长与爱的正
《商业模式案例与公案教学(第一季)》内容简介:本书以魏朱商业模式模型理论为基础,介绍了尚品宅配、挖财、陕鼓、彩生活、金百万
Linux 驱动程序开发实例-第2版 本书特色 Linux设备驱动程序是高级应用程序与硬件设备之间的桥梁。驱动程序开发是软硬件相互结合的技术。本书是一本专门介绍...
《卓越法律人才教育培养的探索与实践》内容简介:本书主要围绕卓越法律人才教育培养撰写论文的主题,阐述卓越法律人才教育培养的总
《陈子涛传》内容简介:本书为雨花台烈士传丛书之一,记叙了陈子涛烈士的一生。陈子涛1920年出生于广西玉林。1938年,初中毕业的陈
《射频通信电路》主要介绍射频电路的设计特点,在设计中应考虑的问题以及射频部分各模块的设计方法。全书分为射频电路设计基础知
kh10269名师讲坛Linux从入门到精通 内容简介 本书是中国台湾优秀it图书作家丰士昌先生的*新力作,总结了作者10余年来使用linux操作系统的经验和技...
JabberisasetofprotocolsexpressedinXML,andanextensibleframeworkthatallowspeoplean...
《20世纪西方女装史经典图鉴(简体中文珍藏版)》以10年为一个附段,用绘图的表现方式,有代表性选取了20世纪各个时期的设计师服装
《跟我学SEO从入门到精通》内容简介:本书从实战出发,理论知识较少,目的是让绝大多数SEO初学者及从业人员直接习得大量可操作性高
《亚细亚生产方式与东方社会发展道路》内容简介:对马克思的亚细亚生产方式的讨论和争论,不仅关系到对这一理论本身的评价和东方社
《山野的日常》内容简介:那些在乡野里度过的时光,如此美妙轻灵。看水流,听鸟鸣,摘野果,晒太阳;云在流,风在走。作者以清新自