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
《雨鼓》内容简介:15世纪,奥斯曼帝国出兵围攻阿尔巴尼亚的城堡,帕夏率领千军万马驻扎城脚,千奇百怪的攻城方式轮番上演,百转千
欢迎您选择一种更高效的学习HTML和CSS的方式。不管您设计和建立新网站,还是想更好地控制现有网站,都可以在《HTML&CSS设计与构建
《JavaScript程序设计实例教程(第2版)》内容简介:本书采用任务驱动模式编写,内容涵盖JavaScript概述、HTML、CSS+DIV应用、Java
《美国陆军图鉴(下册)》内容简介:美国陆军是一支具备全球部署及作战能力的地面军事力量。本书以彩图图解的方式,系统介绍了美国
MATLAB R2016a完全自学一本通-畅销升级版-附赠近150页超值电子书 本书特色 本书面向MATLAB的初中级读者,在介绍MATLAB R2016a集成...
创造力是我们解决问题的源泉。本书试图用图解思维的方法启发设计师积极提升产品创意的能力,而这正是传统的教育方法所忽略的部分
《法学野渡(第四版):写给法学院新生》内容简介:本书作者以一种“传道、授业、解惑”的视角,来审视法学的学习,以“至简、实用
消费已成为中国经济主要发展动力,进一步激活消费的消费金融也上升到国家战略,蕴含70万亿蓝海市场,一大批银行、证券、基金、保
《上海建设全球海洋中心城市发展对策研究报告》内容简介:本书立足于《全国海洋经济发展“十三五”规划》提出的推进上海建设全球海
《WINDOWS游戏编程大师技巧》(第2版)介绍了在Windows环境下进行游戏编程所需用到的各方面知识,作者是著名的游戏开发大师AndrèL
《少年读山海经·千万里江山》内容简介:《山海经》是一部包罗万象的千古奇书,是一座研究古代地理和神话的宝库。“少年读山海经”
本书是继《设计中的设计|全本》之后,广西师范大学出版社推出的全新的原研哉著作。SENSEWARE是原研哉同TOKYOFIBER合作的一个延续
DOS/BIOS注册表/组策略技术手册 本书特色 做电脑的主人,成为人人羡慕的电脑高手!超值的内容:dos命令的精彩应用——探索windows界面下的秘密,bi...
《SEO深度解析》以SEO从业人员普遍存在的疑问、经常讨论的问题、容易被忽视的细节以及常见的错误理论为基础,对SEO行业所包含的各
《复杂数据统计方法——基于r的应用》用自由的日软件分析30多个可以从国外网站下载的真实数据,包括横截面数据、纵向数据和时间序
数据库技术基础及应用第2版 内容简介 本书主要介绍数据库技术的基础及应用。全书共分14章,内容由浅入深、循序渐进,逻辑性强。在理论基础方面,本书从数据管理与数据...
《JavaWeb开发实战1200例(第2卷)》以开发人员在项目开发中经常遇到的问题和必须掌握的技术为核心,介绍了应用JavaWeb进行程序开发
在刚过去的十年我们见证了共享Web和社会媒体的诞生,它们用各种富有创意的方式将人们联系在一起。目前,成千上万的用户忙着在线玩
《自然社交,让情绪不再敏感》内容简介:社交敏感者在生活中最大痛点就是对人际关系的处理总显得力不从心,本书根据近百起实际案例
本书介绍了行为科学(重点是心理学)中用到的基本统计知识:描述性统计、简单的假设验证和最简单的多元统计。全书共分4个部分:第一部