随笔分类 -  零基础学python

摘要:# -*- coding:utf-8 -*- ## Animal is-a object (yes,sort of confusing) look at the extra credit class Animal(object): pass ## 添加在动物的子类狗?? class Dog(Animal): def __init__ (self,name): s... 阅读全文
posted @ 2016-11-28 14:20 听风呤 阅读(375) 评论(0) 推荐(0)
摘要:1 # create a mapping of state to abbreviation 2 states = { 3 'Oregon': 'OR', 4 'Florida': 'FL', 5 'California': 'CA', 6 'New York': 'NY', 7 'Michigan': 'MI' 8 } 9 10 #ct... 阅读全文
posted @ 2016-11-25 23:53 听风呤 阅读(215) 评论(0) 推荐(0)
摘要:1 class song(object): 2 3 def __init__(self, lytics): 4 self.lyrics = lytics 5 6 def sing_me_a_song(self): 7 for line in self.lyrics: 8 print (line) 9 ... 阅读全文
posted @ 2016-11-25 23:53 听风呤 阅读(277) 评论(0) 推荐(0)
摘要:1 from sys import exit 2 3 def gold_room(): 4 print ("This room is full of gold. how much do you take?") 5 6 7 next = input(">") 8 if "0" in next or "1"in next: 9 ... 阅读全文
posted @ 2016-11-23 23:25 听风呤 阅读(327) 评论(0) 推荐(0)
摘要:1 # -*- coding:GBK -*- 2 animals = ["熊", "python", "孔雀", "袋鼠", "鲸鱼", "鸭嘴兽"] 3 4 place1 = animals[0] 5 print ("the place1 animal is %r." % place1) 6 7 no3 = animals[3] 8 print ("the no3 anim... 阅读全文
posted @ 2016-11-23 23:25 听风呤 阅读(801) 评论(0) 推荐(0)
摘要:1 i = 1 2 numbers = [] 3 4 while i <= 8: 5 print ("At the top i is %d" % i) 6 numbers.append(i) 7 i = i * 2 8 print ("Numbers now:",numbers) 9 print ("At the bottom i is... 阅读全文
posted @ 2016-11-23 23:24 听风呤 阅读(362) 评论(0) 推荐(0)
摘要:1 # -*- coding:utf-8 -*- 2 the_count = [1,2,3,4,5] 3 fruits = ['appples', 'oranges', 'pears', 'apricots'] 4 change = [1, 'pennies', 2, 'dimes', 3, 'quarters'] 5 6 #this frist kind of for-loop ... 阅读全文
posted @ 2016-11-23 15:04 听风呤 阅读(126) 评论(0) 推荐(0)
摘要:1 people = 30 2 cars = 40 3 buses = 50 4 5 if cars > people: 6 print ("We should take the cars.") 7 elif cars cars: 13 print ("That's too many buses.") 14 elif buses buses: 20 p... 阅读全文
posted @ 2016-11-23 15:03 听风呤 阅读(125) 评论(0) 推荐(0)
摘要:1 print ("You enter a dark room witn two doors.Do you go through door #1 or door #2?") 2 3 door = input(">>>") 4 5 if door == "1": 6 print ("There 's a giant bear here eating a cheese cak... 阅读全文
posted @ 2016-11-23 15:03 听风呤 阅读(174) 评论(0) 推荐(0)
摘要:1 people = 20 2 cats = 30 3 dogs = 15 4 5 if people cats: 9 print ("Not many cats! The world is saved!") 10 11 if people dogs: 15 print ("The world is dry!") 16 17 18 dogs += 5 19... 阅读全文
posted @ 2016-11-23 15:02 听风呤 阅读(167) 评论(0) 推荐(0)
摘要:1 def break_words(stuff): 2 """This is function will break up words for us.""" 3 words = stuff.split(' ') 4 return words 5 6 def sort_words(words): 7 """sort the words.""" 8 ... 阅读全文
posted @ 2016-11-23 00:10 听风呤 阅读(269) 评论(0) 推荐(0)
摘要:1 之前遇到过的符号汇总 2 常用的powershell命令 3 pwd(打印当前工作目录) 4 hostname(电脑在网络中的名称) 5 mkdir(创建路径/目录/文件夹) 6 cd (加载路径) 7 ls(列出路径下的内容) 8 rmdir(删除路径/目录) 9 pushd (推送路径) 10 popd(弹出路径) 11 cp (复制文件或目录) 12 robocopy... 阅读全文
posted @ 2016-11-21 11:33 听风呤 阅读(143) 评论(0) 推荐(0)
摘要:1 # -*- coding:utf-8 -*- 2 print ("Let's practice everything.") 3 print ('You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.') 4 5 '''poem = """ 6 \tThe lovely world ... 阅读全文
posted @ 2016-11-21 11:33 听风呤 阅读(137) 评论(0) 推荐(0)
摘要:1 # -*-coding:utf-8 -*- 2 def add(a, b): 3 print ("ADDING %d + %d" % (a, b)) 4 return a + b #要理解return的功能 5 6 def subtract(a, b): 7 print ("SUBSTRACTING %d - %d" % (a, b)) 8 ... 阅读全文
posted @ 2016-11-21 11:32 听风呤 阅读(179) 评论(0) 推荐(0)
摘要:1 # -*- coding: utf-8 -*- 2 from sys import argv 3 4 script, input_file = argv 5 6 def print_all(f): 7 print (f.read()) 8 9 def rewind(f): 10 f.seek(0) 11 #seek那个函数不返回值,你pri... 阅读全文
posted @ 2016-11-20 12:05 听风呤 阅读(228) 评论(0) 推荐(0)
摘要:1 # -*- coding:utf-8 -*- 2 def cheese_and_crackers(cheese_count, boxes_of_crackers): 3 print ("You Have %d cheeses!" % cheese_count) 4 print ("You have %s boxes of crackers!" % boxes_of... 阅读全文
posted @ 2016-11-20 00:44 听风呤 阅读(423) 评论(0) 推荐(0)
摘要:1 # this one is like your scripts with argv 2 def print_two(*args): #函数命名规则和变量名一样,只能以字母、数字和下划线组成,数字不可以作为开头 3 arg1, arg2 = args 4 print ("arg1: %r, arg2: %r" % (arg1,arg2)) # 不要混淆TAB键... 阅读全文
posted @ 2016-11-20 00:41 听风呤 阅读(189) 评论(0) 推荐(0)
摘要:1 # -*- coding:utf-8 -*- 2 from sys import argv 3 from os.path import exists 4 5 script, from_file, to_file = argv 6 7 print ("copying from %s to %s" % (from_file, to_file)) 8 9 # we cou... 阅读全文
posted @ 2016-11-19 00:50 听风呤 阅读(194) 评论(0) 推荐(0)
摘要:1 # -*- coding:utf-8 -*- 2 3 from sys import argv 4 5 script, filename = argv #解包变量参数 6 7 print ("we're going to erase %r." % filename) 8 print ("if you don't want that, hit CTRL-C(^c).... 阅读全文
posted @ 2016-11-19 00:48 听风呤 阅读(212) 评论(0) 推荐(0)
摘要:1 # -*-coding:utf-8 -*- 2 from sys import argv 3 4 script, filename =argv #参数赋值 5 6 txt = open(filename) #txt变量为打开文件 7 8 print ("Here's your file %r:" % filename) #在屏幕上提示您的文件名 9 print (... 阅读全文
posted @ 2016-11-17 11:58 听风呤 阅读(170) 评论(0) 推荐(0)