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
《乾隆:政治、爱情与性格》内容简介:中国历史最复杂的皇帝的政治、后宫与人生。读懂了这个人,你就读懂了中国历史,读懂了中国政
《卡通IP时代:品牌卡通形象设计揭秘(第3版·修订版)》内容简介:大IP时代就要来临了,那么到底什么是设计行业的大IP?本书就IP设
《城乡中国(下)》内容简介:《城乡中国》是著名经济学家周其仁关于中国城镇化这一焦点问题的鼎力之作。周其仁《城乡中国》与费孝
《为学跬步集》内容简介:本书是“日知文丛”之一种,是浙江大学历史系教授陈红民所作学术随笔集。内容分为问学之路、情谊绵长、敝
第一本大数据供应链落地之道的权威著作,全球顶级供应链管理专家娜达·桑德斯博士聚焦传统供应链模式向大数据转型,助力工业4.0时
《UML软件建模技术》内容简介:本书以实用、够用为原则,介绍了软件建模技术的基本概念。全书内容由浅入深,逐步展开,并配有大量的
《中国社会建设现代化之路》内容简介:本书中国社会建设现代化,是一个崭新的重大理论与实践课题。作者积多年社会建设理论与实践经
《二十四节气七十二候》内容简介:二十四节气七十二候不仅是一套关于时令、气候、物候变化规律的知识体系,更是属于中国人的时间哲
《潮剧史话》内容简介:潮剧是以潮州方言演唱的地方戏曲剧种,属于宋元南戏的一支,诞生于古潮州,曾有潮泉调、潮腔、潮调、潮音戏
计算机网络 内容简介 本书由浅入深地阐述了计算机网络技术的一些基本概念和基本原理,介绍了当前常用的先进的网络技术以及网络的实际应用,反映了计算机网络技术的一些*...
Photoshop CC自学魔法书-(附光盘) 本书特色 《Photoshop CC自学魔法书》为Photoshop初学者量身打造,是入门级读者快速、全面掌握P...
《走进搜索引擎(第2版)》由搜索引擎开发研究领域三位年轻的博士生精心编写,作者们希望将自己对搜索引擎的理解和实际应用相结合,
该合订本内容包括:合订增值版人物&报道:包括《程序员》的经典品牌栏目名人堂、软件产业、人物专访、软件创业及程序百味等,您即
内容简介本书全面介绍了统计自然语言处理的基本概念、理论方法和最新研究进展,内容包括形式语言与自动机及其在自然语言处理中的
《有没有一首歌让你热泪盈眶》内容简介:每个人的生命中,都有一座青春的巢。少年的巢在美梦里,中年的巢在回忆里,而青年的巢在手
《哲学的中国本土化叙事》内容简介:《哲学的中国本土化叙事》怀着一种积极而开放的情怀探索并追寻本土化的“中国哲学”。“中国哲
《中国移动通信营销案例精选》重点关注中国移动通信的市场战略和市场运作模式。从“沟通从心开始”到“动感地带”客户品牌推出,
《块数据5.0:数据社会学的理论与方法》内容简介:块数据是贵阳发展大数据的理论创新和实践探索的产物,是大数据时代的解决方案。《
《Spring Boot学习指南:构建云原生Java和Kotlin应用程序》内容简介:本书语言简练,既适合刚接触Spring Boot的新手学习基础知识,
《21世纪高等院校电气信息类系列教材•人工神经网络原理及仿真实例》以神经网络结构为主线,以学习算法为副线,详细介绍了神经网络