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
Technologicaladvanceshavebenefitedourworldinimmeasurableways,butthereisanominous...
本书译自《TeachYourselfCin21Days》第6版,该书的前五版都登上了畅销书排行榜,是初学者学习C语言的经典之作。本版按最新的标准
PHP和MYSQLWEB开发(原书第3版) 本书特色 PHP和MySQLWeb开发的“圣经!“我们从来没有购买过如此棒的编程书籍……本书信息量大、容易掌握,而且...
《Python 3面向对象编程(第2版)》内容简介:本书主要介绍如何使用Python3进行面向对象编程。第1~4章介绍面向对象这一编程范式的
新编中文Flash 8实用教程-(第2版) 本书特色 《新编中文Flash8实用教程(第2版21世纪高等院校计算机基础教育规划教材)》由王环、李安宗编著,主要面...
《品牌创造增长》内容简介:怎样建立品牌?怎样挖掘用户的隐性需求?对用户而言,你的产品只是一个名字,还是一个品牌?打造一个知
支持向量机是数据挖掘中的一个新方法。支持向量机能非常成功地处理回归问题(时间序列分析)和模式识别(分类问题、判别分析)等诸多
《小学生同步作文(一、二年级)》内容简介:“名师教你写作文·思维导图系列”丛书是一套集思维导图、形象记忆图、趣味漫画为一体
《中原经济区竞争力报告(2017)》内容简介:本书围绕传统平原农区工业化与经济社会转型的这个主轴,就经济竞争力、社会保障建设、
华为技术认证-HCNP路由交换学习指南 本书特色 本书是配套华为HCNP-R&S的学习指导用书,全书共包含14章,内容包括路由基础、RIP、OSPF、IS-IS...
Forgetschoolmathclass,Flashmathisaboutfun.Itswhatyoudoinyoursparetime-messingaro...
《区块链与智慧物流》内容简介:本书以区块链技术与智慧物流的融合应用为核心,通过剖析智慧物流的发展演进及区块链影响物流系统与
《班克斯的帝国博物学》内容简介:班克斯是英国启蒙运动时期最具影响力的博物学家之一,是迄今为止任期最长的英国皇家学会主席。班
《安藤忠雄连战连败》是安藤忠雄继《安藤忠雄论建筑》一书后,根据其在东京大学建筑系讲课内容整理而成的又一部具有影响力的著作
《爱与真的启示:张爱玲的晚期风格》内容简介:本书主要探讨了张爱玲的晚年生活及其创作体现的“晚期风格”。借助萨义德“晚期风格
Scratch少儿趣味编程 本书特色 scratch是麻省理工学院设计开发的一款编程工具,是适合少儿学习编程和交流的工具和平台,有中文版且完全免费。《scrat...
本书以UML为载体,将面向对象的分析设计思想巧妙地融入建模过程中,通过贯穿全书的实例将软件系统开发过程中方方面面的知识有机地
Manyofthehighesttrafficsitesgetmorethanhalfoftheirtrafficnotthroughthebrowserbut...
《工业大数据分析算法实战》内容简介:《工业大数据分析算法实践》以工业大数据的特点和需求为牵引,阐述了工业大数据分析的算法与
BookDescriptionUbiquitouscomputing--almostimperceptible,buteverywherearoundus--i...