随笔分类 -  Python

摘要:前段时间在LearnStreet网络学习平台上学习了Python入门课程《Python for Beginners》,对Python语言有了一个初步的认识。接下来将以《Python基础教程》(第2版)为主要参考书,对Python语言进行更为深入地学习。《Python基础教程》读书笔记系列文章将针对每一章中重要的知识点进行记录和整理。文章中的编程练习是在基于Python2.7.3版本的交互式解释器中进行的。第1章 基础知识1. 双斜线操作符// (P9)作用:实现整除操作,无论操作数是整数还是浮点数。如:>>> 7.0 / 2.03.5>>> 7.0 // 2 阅读全文
posted @ 2013-03-20 00:34 极客火腿 阅读(797) 评论(0) 推荐(0)
摘要:《Python for Beginners》为LearnStreet上的Python入门课程。本节主要学习内容分为两部分:1. Scoping and Mutability(变量作用域与可变性)2. Classes and Objects(类和对象)Lesson 8 Scoping and Mutability1. Global and Local Variables全局变量和局部变量1 >>> name = "Gladys"2 >>> other_name = "Mario the plumber"3 >> 阅读全文
posted @ 2013-03-18 18:47 极客火腿 阅读(434) 评论(0) 推荐(0)
摘要:《Python for Beginners》为LearnStreet上的Python入门课程。本节主要学习内容为Dictionaries(字典)。Lesson 7 Dictionaries1. Indexing Dictionaries查找字典练习1 def run():2 family = {"dad": 60, "mom" : 58, "brother": 20, "sister" : 15, "me" : 10}3 return family["brother"]4 5 阅读全文
posted @ 2013-03-18 18:28 极客火腿 阅读(465) 评论(0) 推荐(0)
摘要:《Python for Beginners》为LearnStreet上的Python入门课程。本节主要学习内容为Lists and Tuples。Lesson 6 Lists and Tuples1. Length of List计算List变量的长度。1 def run(var):2 #return your code here3 return len(var)4 5 #This is just for you to see what happens when the function is called6 print run([1,2,3,4,5])输出结果:52. Rem... 阅读全文
posted @ 2013-03-14 14:35 极客火腿 阅读(421) 评论(0) 推荐(0)
摘要:《Python for Beginners》为LearnStreet上的Python入门课程。本节主要学习内容为循环语句。一、基本语法1. while循环 下面两种写法是等价的:while flag:while flag == True:2. for循环for x in range(0,3):range(0,3) 执行的有效值范围为[0,1,2], 并且同range(3)是等价的。二、编程练习1. Incrementing and Decrementing1 def run(first, second):2 #your code here3 first +=14 sec... 阅读全文
posted @ 2013-03-09 21:14 极客火腿 阅读(416) 评论(0) 推荐(0)
摘要:《Python for Beginners》为LearnStreet上的Python入门课程。本节主要学习内容为条件语句。Lesson 4 Control Flow and Conditionals1. 第一个Python函数 1 def check_wounds(): 2 #your code here 3 arms = 0 4 if arms == 1: 5 return "tis but a scratch" 6 elif arms == 0: 7 return "flesh wound" 8 else: 9 ... 阅读全文
posted @ 2013-03-06 20:58 极客火腿 阅读(448) 评论(0) 推荐(0)
摘要:《Python for Beginners》为LearnStreet上的Python入门课程。本节主要学习内容为字符串。一、基本概念1. Indexing - References a specific element of a sequence. The first element in a sequence is found at the index 0. To use a single element, call it with [], like this: variable_name[index].首元素的索引值为0。2. Negative Indexing - This allows 阅读全文
posted @ 2013-03-05 19:23 极客火腿 阅读(371) 评论(0) 推荐(0)
摘要:《Python for Beginners》为LearnStreet上的Python入门课程。课程网页设计得很友好,可以边学边练。作为Python的初学者,如果有C语言基础,理解起来也比较容易。该笔记将重点记录Python与C语言不同的语法和编程方法。Lesson 2 Variables, Numbers and Booleans学习笔记:1.关键字(保留字):and, as, assert, break, class, continue, def, del, elif, else, except, exec, finally, for, from, global, if, import, i 阅读全文
posted @ 2013-02-28 15:13 极客火腿 阅读(812) 评论(0) 推荐(0)