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
《职业规划下的高考志愿填报》内容简介:《职业规划下的高考志愿填报》是一本指导考生和家长如何正确填报高考志愿的书,本书分上篇
《超越:上海交通大学ACM班廿年逐梦路》内容简介:本书是上海交通大学ACM班成立二十周年庆典之际,由这二十年中发生在校友身上的,
《无罪辩护:为自由和正义呐喊》内容简介:本书精选了徐昕无罪辩护的办案实录,有推动涉气枪案批复出台的赵春华案、刘大蔚案,影响
《网站入侵与脚本攻防修炼》从“攻”、“防”两个角度,通过现实中的入侵实例,并结合原理性的分析,图文并茂地展现网站入侵与防
每一个渴望学习C++语言的初学者都希望能够有一本全面的,实用的,同时又是生动有趣的入门书。这本入门书可以告诉这些初学者,整个
不同于以往任何时期,如今我们进入了大数据的信息时代。利用合适的工具,我们可以探索数据的价值和意义,挖掘数据背后的模式及其
EPLAN Electric P8教育版使用教程 本书特色 本书按照电气项目的设计流程和特点,讲述了eplan electric p8电气cae绘图及管理软件的...
《产品手绘与创意表达》侧重介绍的是设计师在设计项目案例中绘制的草图,《产品手绘与创意表达》则更倾向于介绍一整套用手绘表达
《高绩效HR必备图表范例》内容简介:当今人力资源管理领域面临诸多新问题、新环境、新理念、新技术,各种名类繁杂的图书也大量涌现
《东瀛之恋:张大千与山田喜美子》内容简介:张大千与山田喜美子的相识大约是在1953年,那时候张大千54岁。1949年以后,张大千移居
《深入核心的敏捷开发:ThoughtWorks五大关键实践》内容简介:本书介绍了ThoughtWorks是如何实践敏捷开发的,主题包括测试驱动开发
《BLOG启示录:WordPress博客建设与经营》分三大部分,共17章。第一部分(1~5章)主要是介绍Web2.0、博客,以及LAMP的安装和架设,
电波传播的特性是研究移动通信系统首先要遇到问题,称动传播环境的特性不仅是所有移动通信理论研究的基础,也更直接关系到工程设
《颠覆完美软件:软件测试必须知道的几件事》是从事软件行业五十余年的GeraldM.Weinberg针对软件测试所写的新作。他在软件项目的
UNIX操作系统教程(第3版) 内容简介 本教材第3版修订中删减了第2版中一些过时的unix技术和描述,增加了针对linux系统设计技术和使用技术的阐述,增加了...
《一分钟管理:影响管理者一生的管理法则(图文版)》内容简介:本书内容涵盖了战略、企业文化、团队建设、用人方法、绩效考核、管
《正面管教》内容简介:不当的管教方式会影响孩子的一生,而有效的管教方式会有益孩子的一生。本书改变了传统的说教、批评、打骂、
《实现技术创新的TRIZ诀窍:40个创新原理》是阿奇舒勒用来介绍如何使用40个创新原理解决技术矛盾的。本版保留了原著的核心部分和尤
Thisthree-volumesetLNCS4554-4556constitutestherefereedproceedingsofthe4thInterna...
算法导论 本书特色 ●算法领域的标准教材,全球多所知名大学选用●MIT名师联手铸就,被誉为“计算机算法的圣经”●教学网址、视频课程及在线学习中心,全方位学习模式...