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
◎内容简介:《计算机:一部历史》,给大众读者写的计算机科普读物,零门槛入门计算机科学。讲述计算机背后鲜为人知的故事,普及
《中国对外贸易环境与贸易摩擦研究报告(2021)》内容简介:本报告的重要特点在于,从国别和区域视角考察中国对外贸易环境与贸易摩
物件的擺放不只是一種視覺的藝術,更是一種溝通的藝術我們睜眼所見的周遭世界,由各種不同的物件組合而成,它們的組合及擺放方式
RichardBlum系统和网络管理员,已经在IT行业工作了22年多。他管理过UNIX、Linux、Novell和微软服务器,用Linuxshell脚本进行过自
《大国经济学》内容简介:起点独特·规模巨大·区域差异显著·治理层级复杂·连接全球的制造业大国 · 改革开放40余年,在一个急速
《理念·制度·人》内容简介:20多年超近距离观察华为与任正非,8年研究积淀解析华为快速崛起的底层逻辑。在本书中,华为公司顾问田
InthetraditionofWhoOwnstheFuture?andTheSecondMachineAge,anMITMediaLabscientistim...
《3D游戏编程大师技巧》是游戏编程畅销书作者AndréLaMothe的扛鼎之作,从游戏编程和软件引擎的角度深入探讨了3D图形学的各个重要
《新编电信技术概论》讲述现代电信的相关概念、涉及的关键技术及工作原理。全书共分13章。第一章基本概念,介绍信号的频域分析、
《网站开发专家·Google成功背后的技术:Ajax网页程序设计》详细介绍了Google背后的技术——Ajax,主要内容包括:Ajax简介、Ajax基
《宋词背后那些有趣的灵魂》内容简介:《宋词背后那些有趣的灵魂》是一本透过词人人生来品读古典诗词之美的书,囊括了十位宋代优秀
《理财中的经济学》内容简介:每个人的生活都离不开金钱,管理金钱即理财。掌握好理财的技能,对于提高个人与家庭的生活质量大有帮
《一本书读懂内部审计》内容简介:内部审计工作涉及公司经营的每一个环节,小到一份经济合同、一张财务报表,大到业务流程、部门绩
《漫画图解人工智能》内容简介:漫画式AI通识课 轻松get人工智能核心问题 ☆ 在AI领域深耕多年的专家首次面向大众讲述 人工智能已经
Excel VBA编程实战宝典-附DVD光盘 本书特色 “开发宝典丛书”是由清华大学出版社为软件开发爱好者精心打造的一套软件开发百科全书。丛书强调“全面...
《R语言数据分析与挖掘实战》内容简介:本书共16章,分三个部分:基础篇、实战篇、提高篇。基础篇介绍了数据挖掘的基本原理,实战篇
本书以作者自身学习、使用模式和多年来为软件开发人员(包括面向对象技术老兵和新手)讲授模式的经验为基础撰写而成。首先概述了模
信息系统项目管理师考试辅导-(针对下午考试) 内容简介 本书按照人力资源和社会保障部、工业和信息化部全国计算机技术与软件专业技术资格(不平)考试要求编写。作者依...
《Maya 2013完全学习手册》内容简介:本书是“完全学习手册”系列图书中的一本。《Maya 2013完全学习手册》遵循人们的学习规律和方
《指尖上的会计》内容简介:学会计并不难,难的是“学得开心,用得顺手”。那么,面对那些晦涩难懂的会计术语以及财税处理工作,如