Think Python - Chapter 03 - Functions】的更多相关文章

3.1 Function callsIn the context of programming, a function is a named sequence of statements that performs a computation. When you define a function, you specify the name and the sequence of statements. Later, you can “call” the function by name. We…
<Web Scraping with Python> Chapter 1 & 2: Your First Web Scraper & Advanced HTML Parsing BeautifulSoup Key:     P5: urlib or urlib2?  If you’ve used the urllib2 library in Python 2.x, you might have noticed that things have changed somewhat…
python进阶03 继承 一.继承 课堂练习:假设你正在参与一个魔幻类角色游戏的开发,公司需要腻味这个游戏设计两个角色的类: a.剑士 属性:1.角色名:2.角色等级:3.生命值:4.攻击力 行为:物理攻击 b.法师 属性:1.角色名:2.角色等级:3.生命值:4.法术强度 行为:1.法术攻击:2.治疗 #首先定义一个剑士类 class SwordsMan:#定义一个剑士类 def __init__(self,name,lever,blood): #初始化剑士的名字,等级,血量 self.na…
本篇记录自己的笔记Python的generator functions和yield理解表达式. 1. Generator Functions Python支持的generator functions语法同意我们定义一个行为与iterator类似的函数,它能够被用在须要循环调用的场合. 与普通函数相比,generator functions仅仅是在函数定义中多了1个yield表达式.除此之外,没有其他特别之处.        当generator函数被创建时.python解释器会自己主动为它实现i…
Python模块03/re模块 内容大纲 re模块(正则表达式) 1.re模块(正则表达式) import re s = "meet_宝元_meet" print(re.findall("meet",s)) 从字符串中全部查找内容,返回一个列表 s = "meet_宝元_meet123" print(re.findall("\w",s)) 查找数字,字母(中文),下划线 # s = "meet_宝元_meet123!…
Python函数03/函数名的第一类对象及使用/f 格式化/迭代器/递归 目录 Python函数03/函数名的第一类对象及使用/f 格式化/迭代器/递归 内容纲要 1.函数名的第一类对象及使用 2.f 格式化 3.迭代器 4.递归 5.今日总结 6.今日练习 内容纲要 1.函数名的第一类对象及使用 2.f格式化 3.迭代器 4.递归 1.函数名的第一类对象及使用 第一类对象的的特殊点: 1.可以当做值赋值给变量 # def func(): # print(1) # # print(func) #…
Python面向对象03 /继承 目录 Python面向对象03 /继承 1. 初识继承 2. 单继承 3. 多继承 4. 总结 1. 初识继承 概念:专业角度:如果B类继承A类,B类就称为子类,派生类,A类就称为父类,超类,基类 种类:单继承,多继承 面向对象的三大特征:继承,封装,多态 继承的优点: 减少重复的代码 增加类之间的耦合性(不宜多,宜精) 使代码更清晰,合理化 2. 单继承 定义:只有一个父类 执行父类的属性和方法: 1.类名执行父类的属性和方法 2.派生类对象执行父类的属性和方…
(python函数03)zip()函数 zip是用来压缩的,它接受一系列可迭代的对象作为参数,将对象中对应的元素打包成一个个元组(tuple),然后返回有这些tuples组成的对象,可强制转化为列表和字典.若传入参数的长度不等,则返回list的长度和参数中长度最短的对象相同. 示例代码01  list_str = ['a', 'b', 'c', 'd'] list_num = [1, 2, 3, 4] list_new = zip(list_num, list_str) print("zip结果…
16.1 TimeAs another example of a user-defined type, we’ll define a class called Time that records the time of day. The class definition looks like this: class Time(object): """Represents the time of day. attributes: hour, minute, second &qu…
In this chapter I present classes to represent playing cards, decks of cards, and poker hands.If you don't play poker, you can read about it at http://en.wikipedia.org/wiki/Poker, but you don’t have to; I’ll tell you what you need to know for the exe…