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
本书内容包括三部分:集合论、图论、近世代数。全书共分十五章,讨论了集合及其运算、映射、关系、无穷集合及其基数、模糊集合论
《海洋大百科:彩绘图解版》内容简介:本书是一本系统认识海洋、探索海洋、开拓海洋的彩色图文版海洋百科全书。本书共分6章,具体内
《当代设计研究理念》主要内容:设计理念和方法是当今使用者体验研究(UserExperience:Research,中文也译作“用户体验研究”)
《统计挖掘与机器学习(原书第3版)》内容简介:本书创造性地汇编了数据挖掘技术,将统计数据挖掘和机器学习数据挖掘进行了区分,对
《德国设计图典》是艺术设计专业的入门参考书,旨在通过简单的百科式构架和丰富直观的图片资料来帮助初学者接触、理解和掌握德国
《TensorFlow与自然语言处理应用》内容简介:自然语言处理(NLP)是计算机科学、人工智能、语言学关注计算机和人类(自然)语言之间
MobileInteractionDesignshiftsthedesignperspectiveawayfromthetechnologyandconcent...
Thisinnovativetextpresentscomputerprogrammingasaunifieddisciplineinawaythatisbot...
《教育3.0》内容简介:科技的发展、时代的巨变给当下的教育行业带来了巨大的挑战,工业时代的教育方式早已过 时,未来的教育如何发
《Kotlin从入门到进阶实战》内容简介:本书从Kotlin语言的基础语法讲起,逐步深入到Kotlin进阶实战,并在最后配合项目实战案例,重
《博悟空间》内容简介:中国博物馆事业蓬勃发展,目前注册有5000多座博物馆,每年举办展览将近3万个。如何将更好品质、更好体验的展
《HTML5+CSS3精致范例辞典(全彩印刷)》是专为希望成为网页设计师的学习者打造的工具书,书中详细说明了设计网页所需的HTML标记语
本书为日本长销商品的设计细节透析,回顾了日本各领域长销商品的注重消费者体验的设计变迁,以详尽的图解形式对比设计的变与不变
清新风-CG插画技法 本书特色 cg插画是一种新兴的绘画技术,主要应用于漫画和游戏领域,因其夺目的效果而得到众多二次元爱好者的认可和推崇。本书采用清新、绚丽、雅...
《牛妞与羊爸》内容简介:如何关爱孩子?如何教育儿女?历来是家庭生活中的大事,也是父母最上心最挠头的问题。羊爸为牛妞写了19年
《汽车材料及轻量化趋势》内容简介:作为提高汽车燃油经济性的手段之一,轻量化并不是新鲜的技术名词。从20世纪70年代以来,汽车轻
《不烦恼的月子生活:开心做妈妈》内容简介:对新妈妈而言,宝宝的出生并不意味孕产生活的结束,而是一段影响终身的坐月子生活的开
程序员你伤不起 本书特色 你要有过硬的技术,让客户相信你,觉得这个事情你是专家,让你来做没错,你要时刻让自己的技术超出平常人的水平。我曾经也泄气过,但是我经常能...
《王阳明:一切心法》内容简介:本书是一部诚意之作,它权威、有趣、真挚,易懂,只为让你了解真正的而不是为误解的王阳明,了解“
The Adobe Illustrator CS2 Wow!Book 内容简介 本书由基础、提示、练习、技巧、画廊和参考资料等六个部分融合而成,每部分都是Ill...