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
《中国财政科研教学的“老兵”:邓子基传》内容简介:邓子基是我国著名经济学家、财政学家和教育家、中华人民共和国财政学奠基人和
JenniferCampbell是多伦多大学计算机科学系高级讲师,本书所基于的课程就是由她创建的。PaulGries是多伦多大学计算机科学系高级讲
《商业模式案例与公案教学(第一季)》内容简介:本书以魏朱商业模式模型理论为基础,介绍了尚品宅配、挖财、陕鼓、彩生活、金百万
《烹饪原料》内容简介:本书重点介绍了各类烹饪原料的形态特征、性质特点、产地与产季、组织结构、品质检验、贮存与保管、烹饪运用
最权威的Python教程,由Python作者GuidovanRossum主笔,有少许学院味道。中文电子版由刘鑫、李梦夷翻译。英文原稿网址:http://d
《无罪辩护:为自由和正义呐喊》内容简介:本书精选了徐昕无罪辩护的办案实录,有推动涉气枪案批复出台的赵春华案、刘大蔚案,影响
《哄哄你我就高兴了》内容简介:活得好不好,活得快不快乐,关键在于你是不是活明白了,是不是活得无怨无悔,是不是活得没有遗憾,
《李商隐诗选》内容简介:李商隐,字义山,号玉溪生,又号樊南生,是唐朝后期杰出诗人之一,与杜牧并称“小李杜”。因卷入朋党斗争
《无伤跑法》内容简介:近年来,跑步引发了全民运动的热潮,成为大众参与度最高的运动之一。然而,除了健康、积极的生活方式,跑步
Thisbookprovidesapracticalapproachtounderstandingimplementationsofnon-strictfunc...
《水墨畲影·浙江省畲族元素钢琴作品集》内容简介:内容丰富,构思新颖,整部音乐作品集紧紧围绕着畲字做文章,说起畲字就不得不提
《普仁明堂示扶正:贺氏针灸理论精华及临床实录》内容简介:本书分为两部分。上篇主要讲述了贺氏针灸流派的理论精华:三通法(微通
《一步步写嵌入式操作系统:ARM编程的方法与实践》是一本介绍怎样去实际编写一款嵌入式操作系统的书,所涉及的内容包括操作系统基
《学习PHP和MySQL》内容全面,既解释了各种基础概念,又讨论了实现各种特定功能的具体细节,并附有示例应用来演示如何综合使用这
《游戏经济:以社交媒体游戏促进业务增长》内容简介:社交媒体游戏以其富有曲折的故事情节、情感体验和互动性,令用户着迷,如果能
KH10067 Photoshop CS5影像圣经 本书特色 本书编写的目的,是为读者解析经典软件photoshop的使用方法,提供操作上的重点和难点信息,实战...
《支付方法论》内容简介:这是一部从产品、运营、业务、技术4个维度全面讲解支付理论与实操的著作。详细阐述了如何通过支付系统建设
《数据中台:让数据用起来》内容简介:这是一部系统讲解数据中台建设、管理与运营的著作,旨在帮助企业将数据转化为生产力,顺利实
《绘设计:建筑快题设计完全解析》内容简介:这是一本对建筑快题设计进行全面解析的综合教程,以建筑快题设计方法为基础,以解决建
《齐白石鱼虫册》内容简介:“南山册页”是浙江摄影出版社自主选编的一套名家册页小品集,以散页函套的装帧形式出版,题材集中于历