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
《OPNETModeler与网络仿真》旨在帮助读者在阅读软件帮助文件时,更方便快捷地使用OPNETModeler(下文将其简称为OPNET)。全书共分为
《多工位级进模实例精选》内容简介:本书结合现代模具企业对模具设计师的工作要求,以先进、实用、通用为目的。全书分为2篇,每篇各
2010年編輯最愛商業書籍。──財富雜誌2010年書評最愛書籍。──紐約客雜誌2010年度商業與投資類十大好書。──亞馬遜書店2010年
《被颠覆的汽车帝国:中国汽车电商与车联网生态报告》内容简介:本书对移动互联网时代下的车企的现状及当代车企的营销活动进行了深
《CSS网页布局创意课》的第1部分,收录了若干网页设计权威专家所著的特写文章,其中涵盖了新的CSS3属性及针对各种屏幕大小进行设
photoshop CS6从入门到精通(全彩版) 本书特色本书讲述了学习photoshop cs6所需的相关知识,主要包括认识photoshop cs6、使用p...
Ajax,orAsynchronousJavaScriptandXML,explodedontothesceneinthespringof2005andrema...
本书是由40多位国外游戏开发行业最为优秀的程序员撰稿的技术文集。每篇文章都针对游戏编程中的某个特定问题,不仅提供了解决思路
《地理信息技术与地理教学的整合》内容简介:本书总结了地理信息技术应用于地理教学的研究成果,从理论上探讨了地理信息技术的教学
如何判断何种灯光设计能最大限度地满足居室需要,应该使用向下的灯光?向上的灯光?地面射灯或是墙面射灯?应该选用何种类型的灯
《学术家园(精)》内容简介:《学术家园》是《人民政协报》的品牌周刊,很好地体现了政协“学者云集,名家荟萃”的构成特点。今年
一本预示着Web4.0网络大时代来临的开创性读物在这个重视营销宣传的社会,只要利用好互联网,就能让你商业上的竞争对手抓狂。大脑
我们为什么不谈北欧设计,仅谈丹麦设计?因为从历史上看,不但北欧四国属于以丹麦为中心的北欧大帝国,就连整个英格兰,苏格兰的
ThebookcoverstheforthcomingPylons0.9.7releaseandisavailbleforfreetoreadhereonlin...
{BookDescription}CutascenefromtheUSANetworktelevisionseriesMonk,createapromoforS...
FirefoxHacksisidealforpoweruserswhowanttotakefulladvantageofFirefoxfromMozilla,t...
本书收集了作者在试验心理学这一研究领域发表过的五篇最著名的论文以及其他若干论文。每篇旧论文后面都有作者的后记,回顾该文发
Django Web应用开发实战 本书特色 本书由一线资深软件工程师结合多年Python开发经验倾力编撰,集Django架站、案例实践、前瞻技术于一体,是一本精...
卷1 协议-TCP/IP详解-(英文版.第2版) 本书特色 ·w. richard stevens传奇般的tcp/ip指南,现在被顶级网络专家kevin r.f...
《世界想象:西学东渐与明清汉文地理文献》内容简介:16至19世纪的西学东渐,使中国社会进入一个独特的文化转型期。此间所形成的汉