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
《五子连珠必胜法》经日本国虹有社授权,译自日本连珠社已故理事长新井华石九段经典著作《连珠必胜法》一书。内容阐述和介绍五子
stephenc.dewhurst,贝尔实验室最早的c++程序员之一。他有着20多年的c++应用经验,涉及的应用领域包括编译器设计、安全交易、电子
大数据下并行知识约简与知识获取 本书特色 本书针对大数据的数据体量大、数据类型繁多、处理速度快、价值密度高等特点,以粒计算方法为理论基础,以经典粗糙集模型和区间...
《Android开发实战》内容简介:本书由一线资深软件开发工程师基于目前广泛使用的Android 6/7和Android Studio 2.x开发环境倾力编撰
《长三角区域一体化发展战略研究》内容简介:本书通过对比分析两大经济区制造业,特别是战略性新兴和高技术产业的发展情况,以及制
《JavaWeb入门经典》以初学者为核心,全面介绍了JavaWeb开发中常用的各种技术。内容排列上由浅入深,让读者循序渐进掌握编程技术
《梁衡红色经典散文选(增订本)》内容简介:这是一部以政治人物为主的散文集。全书以人物为线,勾勒出近百年中国社会进步的脉络,
软件设计师2009至2014年试题分析与解答-全国计算机技术与软件专业技术资格(水平)考试指定用书 本书特色软件设计师级考试是全国计算机技术与软件专业技术资格(...
《抽象中的形象:图形的故事》内容简介:本书故事的引人入胜与数学原理的巧妙结合,会产生一种奇特的反应,让读者在故事的流连忘返
《PyTorch深度学习实战》内容简介:虽然很多深度学习工具都使用Python,但PyTorch库是真正具备Python风格的。对于任何了解NumPy和s
《基于无线自组网的应急通信技术》内容简介:应急通信是为应对自然灾害或公共突发事件而提供的特殊通信机制和手段。本书以突发紧急
从0起飞五笔打字易学通 内容简介 本书内容包括:键盘的历史和种类、五笔字型输入法程序的使用、掌握五笔字型的基础知识、使用五笔输入法进行汉字的输入等。从0起飞五笔...
《手绘设计草图表现技法》内容简介:本书阐述了手绘图透视表现的基本原理、制图方法和物体的质感表现等,介绍了多种手绘图表现的画
Emotion.Ego.Impatience.Stubbornness.Characteristicslikethesemakecreatingsitesand...
《华为内训(新版)》内容简介:翻开《华为内训》,您将步入一个炫目恢宏的商业世界,由此洞悉华为内部独特的管理经营机制。作为世
《吃食和文学》内容简介:本书收录了汪曾祺关于美食的经典散文集,包括家乡的食物、地方风味、家常小菜、民间特色美食等内容,无论
《书法讲座》内容简介:本书以通俗易懂的讲座形式,全面讲述书法的发展历程、书法的美学、书法创作实践等。不仅重形而下之技法,更
《金融激荡300年》内容简介:本书从经济学角度解读历史和政治,追溯300年金融激荡的进程,解读金融的力量,回答金融的走向,是一本
逻辑与计算机科学哲学 内容简介 本书是作者自2000年以来在科学技术哲学领域研究的一些成果集,分为逻辑与思维和计算机科学哲学两编,主要包括归纳思维、逻辑真探讨、...
IfyouareacompilerdeveloperwhowantstousethestrongoptimizationtechniquesofLLVMandl...