python3.0
剪草的Kross
这个作者很懒,什么都没留下…
展开
-
python系统学习日记 L6 字符串和文本
书中代码import datetimex = "There are %d types of people ." % 10binary = "binary"do_not = "don't"y = "Those who know %s and those who %s." % (binary, d原创 2019-03-04 21:36:22 · 114 阅读 · 0 评论 -
python系统学习日记 L18 函数function
函数可以做三件事:1、它们给代码片段命名,就跟“变量”给字符串和数字命名一样。2、它们可以接受参数,就跟你的脚本接受 argv 一样。3、通过使用 #1 和 #2,它们可以让你创建“微型脚本”或者“小命令”。书中代码:# this one is like your scripts with argvdef print_two(*args): arg1, arg2 = args pr...原创 2019-03-07 09:23:03 · 115 阅读 · 0 评论 -
python系统学习日记 L19 函数和变量类型
通过这个练习,我们给函数 cheese_and_crackers ()传递很多的参数,然后在函数里把它们打印出来。我们可以在函数里用变量名,可以在函数里做运算,甚至可以将变量和运算结合起来。从一方面来说,函数的参数和我们的生成变量时用的 = 赋值符类似。事实上,如果你可以用 = 给一个东西命名,你也就可以将其作为参数传递给一个函数。书中代码:def cheese_and_crackers(ch...原创 2019-03-07 09:23:41 · 135 阅读 · 0 评论 -
python系统学习日记 L20 函数和文件
书中代码:from sys import argvscript, input_file = argvdef print_all(f): print f.read()def rewind(f): f.seek(0)def print_a_line(line_count, f): print line_count, f.readline()current_file = open...原创 2019-03-07 09:23:58 · 143 阅读 · 0 评论 -
python系统学习日记 L27~L30 布尔值判断
书中代码:L30:people = 30cars = 40trucks = 15if cars > people: print "We should take the cars."elif cars < people: print "We should not take the cars."else: print "We can't decide.&am原创 2019-03-11 09:30:27 · 129 阅读 · 0 评论 -
python系统学习日记 L31
书中代码:print "You enter a dark room with two doors. Do you go through door #1 or door #2?"door = raw_input("> ")if door == "1": print "There's a giant bear here eating a cheese c原创 2019-03-11 09:30:49 · 118 阅读 · 0 评论 -
python系统学习日记 L33 while循环
书中代码:i = 0numbers = []while i < 6: print "At the top i is %d" % i numbers.append(i) i = i + 1 print "Numbers now: ", numbers print "At the bottom i is %d" % iprint "The原创 2019-03-11 09:31:10 · 115 阅读 · 0 评论 -
python系统学习日记 L32 循环和列表
书中代码:这节习题,我们将使用 for循环来创建并打印一些列表。使用 for 循环之前,你需要在某个位置存放循环的结果。最好的方法是使用列表(list),顾名思义,列表就是一个按顺序存放东西的容器。书中代码:the_count = [1, 2, 3, 4, 5]fruits = ['apples', 'oranges', 'pears', 'apricots']change = [1, ...原创 2019-03-11 09:44:20 · 145 阅读 · 0 评论 -
python系统学习日记 L35 分支和函数
书中代码:from sys import exitdef gold_room(): print "This room is full of gold. How much do you take?" choice = raw_input("> ")if "0" in choice or "原创 2019-03-11 09:44:37 · 173 阅读 · 0 评论 -
python系统学习日记 L39 字典
字典dict 所作的,是让你可以通过任何东西找到元素,不只是数字。字典可以将一个物件和另外一个东西关联,不管它们的类型是什么书中ex39.py代码修改为:# create a mapping of state to abbreviationstates = { 'Oregon': 'OR', 'Florida': 'FL', 'California': 'CA', 'New York...原创 2019-03-11 09:45:21 · 139 阅读 · 0 评论 -
python系统学习日记 L21 函数的返回值
书中代码:def add(a, b): print "ADDING %d + %d" % (a, b) return a + bdef subtract(a, b): print "SUBTRACTING %d - %d" % (a, b) return a - bdef multiply(a, b): print "MULTIPLYING %d * %d" % (a, b)..原创 2019-03-07 18:03:39 · 193 阅读 · 0 评论 -
python系统学习日记 L22~L24 练习
L22~L23:无L24:书中代码:print "Let's practice everything."print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'poem = """\tThe lovely worldwith logic so firmly planted...原创 2019-03-07 18:04:03 · 172 阅读 · 0 评论 -
python系统学习日记 L25 import导入
本章的练习需要将自己定义的函数导入到 python 里通过自己执行函数的方式运行import的代码ex25.py 如下:def break_words(stuff): """This function will break up words for us.""" words = stuff.split('') return wordsdef原创 2019-03-07 18:04:31 · 231 阅读 · 0 评论 -
python系统学习日记 L26 修正改错
书中L26是改错习题,对一段有问题的代码进行改正书中代码:def break_words(stuff): """This function will break up words for us.""" words = stuff.split(' ') return wordsdef sort_words(words): """Sor原创 2019-03-07 18:04:51 · 311 阅读 · 0 评论 -
python系统学习日记 L17 更多文件操作
书中代码:from sys import argvfrom os.path import existsscript, from_file, to_file = argvprint "Copying from %s to %s" % (from_file, to_file)# we could do these two on one line, how?in_file = open(fr...原创 2019-03-07 09:21:34 · 175 阅读 · 0 评论 -
python系统学习日记 L16 读写文件
下面的命令,是你应该记住的命令:close – 关闭文件。跟你编辑器的 文件->保存… 一个意思。read – 读取文件内容。你可以把结果赋给一个变量。readline – 读取文本文件中的一行。truncate – 清空文件,请谨慎使用该命令。write(‘stuff’) – 将stuff写入文书中代码:from sys import argvscript, filenam...原创 2019-03-07 09:19:43 · 151 阅读 · 0 评论 -
python系统学习日记 L7 更多的打印(输出)
书中代码print "Mary had a little lamb."print "Its fleece was white as %s." % 'snow'print "And everywhere that Mary went ."print "." * 10 # what'd that do ?end1 = "C&quo原创 2019-03-04 21:36:58 · 99 阅读 · 0 评论 -
python系统学习日记L8 打印,打印
书中代码如下:formatter = "%r %r %r %r"print formatter % (1, 2, 3, 4)print formatter % ("one", "two", "three", "four")print formatter % (True, False, False, True)print原创 2019-03-04 21:37:56 · 132 阅读 · 0 评论 -
python系统学习日记L9 打印,打印,打印
书中代码:# Here's some new strange stuff ,remember type it exactlydays = "Mon Tue Wed Thu Fri Sat Sun"months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"print "Here are the days: ", daysprint "原创 2019-03-04 21:38:24 · 109 阅读 · 0 评论 -
python系统学习日记L10 那是什么?转义字符
书中代码:tabby_cat = "\tI'm tabbed in."persian_cat = "I'm split\non a line."baskslash_cat = "I'm \\ a \\ cat."fat_cat = '''I'll do a list"\t* Cat food\t* Fishies\t* Catnip\n\t* Grass'''原创 2019-03-04 21:38:52 · 140 阅读 · 0 评论 -
python系统学习日记 L11~L12 python2.x与3.x 输入函数input的区别
书中代码:print "How old are you?",age = raw_input()print "How tall are you?",height = raw_input()print "How much do you weigh?",weight = raw_input()print "So, yo原创 2019-03-05 17:50:40 · 124 阅读 · 0 评论 -
python系统学习日记 L13 参数, 解包, 变量
书中代码:from sys import argvscript, first, second, third = argvprint "The script is called:", scriptprint "Your first variable is:", firstprint "Your second variable is:", secondprint "You原创 2019-03-05 17:51:13 · 308 阅读 · 0 评论 -
python系统学习日记 L14 提示和传递
书中代码:from sys import argvscript, user_name = argvprompt = '> 'print "Hi %s, I'm the %s script." % (user_name, script)print "I'd like to ask you a few questions."print "Do you like me %s?&quo原创 2019-03-05 17:51:37 · 157 阅读 · 0 评论 -
python系统学习日记 L15 读文件
书中代码原创 2019-03-05 17:52:00 · 113 阅读 · 0 评论 -
python系统学习日记前言——笨办法学python
笨办法学python 下载链接 链接:https://pan.baidu.com/s/10C-sTeedEPY5FKpCpto6gw提取码:nk3v书中以python2的例子都是以python2实现的,我将在接下来的文章中改为python3的语法实现...原创 2019-03-03 21:36:25 · 122 阅读 · 0 评论 -
python系统学习日记 L1~L2
文章内容是根据笨办法学python课程中的代码修改为适合python3的代码书中练习一和练习二 py2和py3的区别主要在于print函数在Python2和Python3中都提供print()方法来打印信息,但两个版本间的print稍微有差异主要体现在以下几个方面:1.python3中print是一个内置函数,有多个参数,而python2中print是一个语法结构;2.Python2打印...原创 2019-03-03 21:36:57 · 271 阅读 · 0 评论 -
python系统学习日记 L3 数字和数学
数学运算符号+ plus 加号- minus 减号/ slash 斜杠 除法* asterisk 星号 乘法% percent 百分号 模除布尔值运算:< less-than 小于号> greater-than 大于号<= less-than-equal 小于等于>= greater-than-equal 大于书中代码改为print("I will...原创 2019-03-03 21:37:25 · 195 阅读 · 0 评论 -
python系统学习日记 L4 变量和命名
书中代码如下:cars = 100space_in_a_car = 4.0drivers = 30passengers = 90cars_not_driven = cars - driverscars_driven = driverscarpool_capacity = cars_driven * space_in_a_caraverage_passengers_per_car =...原创 2019-03-03 21:38:00 · 165 阅读 · 0 评论 -
python系统学习日记 L5 更多的变量和打印
书中代码:my_name = 'Zed A . Shaw'my_age = 35 # not a liemy_height = 74 # inchesmy_weight = 180 # lbsmy_eyes = 'Blue'my_teeth = 'White'my_hair = 'Brown'print "Let's talk about % s." % my_namep...原创 2019-03-03 21:38:33 · 254 阅读 · 0 评论 -
python系统学习日记 L40 模块, 类和对象
书中代码:原创 2019-03-12 10:14:14 · 98 阅读 · 0 评论