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
《写好论文》内容简介:怎样写好论文? 一直以来,“感悟式教授”和“体悟式学习”是论文写作主要的提升模式。随着学术水平的提升和
KaiHwang(黄铠)拥有加州大学伯克利分校博士学位。现为美国南加州大学电子工程与计算机科学终身教授,并先后担任清华大学计算机
《新四书与新儒学》内容简介:儒家的仁义思想不只是由仁而义,还包括由义而仁,前者是孟子的“居仁由义”,是由道德而政治,后者是
每天,google都要测试和发布数百万个源文件、亿万行的代码。数以亿计的构建动作会触发几百万次的自动化测试,并在好几十万个浏览
《我们都是科学家:那些妙趣横生而寓意深远的科学实验(修订版)》内容简介:本书让你通过身边的有趣实验完成前沿科技的奇妙体验。
《弓箫缘·石榴记》内容简介:《弓箫缘》初唐年间,筹建北庭都护府的四十万石粮草意外遭劫,陈澌奉李渊之命调查此案。塞外草原一晚
《学习PHP和MySQL》内容全面,既解释了各种基础概念,又讨论了实现各种特定功能的具体细节,并附有示例应用来演示如何综合使用这
AuniqueresourcetohelpsoftwaredeveloperscreateadesirableuserexperienceToday,top-f...
《发明改变生活》内容简介:在璀璨的人类文明中,各式各样的发明层出不穷,为我们的生活带来了日新月异的变化。那发明是如何改变生
《聪明女人的口才修炼课》内容简介:在人际关系互动频繁的时代,说话技巧变得愈来愈重要。女人想要拥有好人缘,在职场和情场里无往
本书共分为10章,系统全面地介绍了HTML5规范的核心内容,以及这些内容在当前浏览器中的支持情况,并告知开发者如何在当前的环境下
《Linux内核观测技术BPF》内容简介:本书是一本面向系统工程师的实践指南,皆在帮助他们获得Linux内核中BPF虚拟机的专业知识。通过
《脑卒中:与时间赛跑》内容简介:一定要知道的脑卒中预防与康复知识,上海交通大学医学院附属瑞金医院康复团队暖心制作。全书通过
Thepurposeofthisbookistohelpyouunderstandhowtoprogramshared-memoryparallelmachin...
数码照片后期修饰高级篇 内容简介 本书以27个经典实例进行分析,具体包括:制作自己的肖像邮票、制作插画效果、制作速绘效果、制作水彩效果、制作动感背景效果、制作水...
哈特穆特•艾斯林格HartmutEsslinger,艾斯林格是全球工业设计教父,世界顶级创意咨询公司青蛙公司创始人,公认的高科技设计领域首
本书全面介绍iPad,教你玩转iPad,全书主要分iPad基本QuickView、影音娱乐的世界中心—iTunes、数字阅读篇、珍藏回忆篇、随身娱乐
深入浅出数据分析 本书特色 我们生活在数据的天地里,你的工作就是淋漓尽致地发挥数据的作用。从哪里起步?米尔顿编著的《深入浅出数据分析》将为你提供帮助:利...
《所罗门王的宝藏》内容简介:犹太民族的所罗门国王既是智慧的代表,又是财富的象征。他死后多少个世纪以来,人们一直在寻找这批古
ComputerVisionisfastbecominganimportanttechnologyandisusedinMarsrobots,nationals...