随笔分类 - Learn Python The Hard Way
摘要:这里需要认真学习一下。
阅读全文
摘要:class Parent(object): def __init__(self, **kwargs): if kwargs.has_key('age'): self.__age = kwargs['age'] if kwargs.has_key...
阅读全文
摘要:## Animal is-a object (yes, sort of confusing) look at the extra creditclass Animal(object): pass## ??class Dog(Animal): def __init__(self, name): #...
阅读全文
摘要:import randomfrom urllib import urlopenimport sysWORD_URL = "http://learncodethehardway.org/words.txt"WORDS = []PHRASES = { "class ###(###):": "Mak...
阅读全文
摘要:class Song(object): def __init__(self, lyrics): self.lyrics = lyrics def sing_me_a_song(self): for line in self.lyrics: print linehappy_bda...
阅读全文
摘要:# create a mapping of state to abbreviationstates = {'Oregon': 'OR','Florida': 'FL','California': 'CA','New York': 'NY','Michigan': 'MI' }# create a b...
阅读全文
摘要:class Thing(): def test(self, hi): print 'hi'a.test('hello')以上为修改后的代码ten_things = "Apples Oranges Crows Telephone Light Sugar"print "Wait th...
阅读全文
摘要:anddelfromnotwhileaselifglobalorwithassert #http://stackoverflow.com/questions/5142418/what-is-the-use-of-assert-in-pythonThe assert statement/functio...
阅读全文
摘要:from sys import exitdef gold_room(): print "This room is full of gold. How much do you take?" next = raw_input("> ") if "0" in next or "1" in...
阅读全文
摘要:自己的几个list常用用法。mylist = [i for i in range(10)]mylist.pop(-1)mylist.append(9)mylist_1 = [i for i in range(10,20)]mylist_2 = zip(mylist, mylist_1)mylist....
阅读全文
摘要:while用起来不如for安全。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_count = [1, 2, 3, 4, 5]fruits = ['apples', 'oranges', 'pears', 'apricots']change = [1, 'pennies', 2, 'dimes', 3, 'quarters']# this first kind of f...
阅读全文
摘要: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 ...
阅读全文
摘要:if __name__ == '__main__': a = 100 if a > 90: print "90" elif a > 80: print '80' elif a > 70...
阅读全文
摘要:people = 20cats = 30dogs = 15if people cats: print "Not many cats! The world is saved!"if people dogs: print "The world is dry!"dogs += 5if people...
阅读全文
摘要:def break_words(stuff): """This function will break up words for us.""" words = stuff.split(' ') return wordsdef sort_words(words): """Sorts t...
阅读全文
摘要: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...
阅读全文
摘要: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): ...
阅读全文
摘要: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): pri...
阅读全文
摘要:def cheese_and_crackers(cheese_count, boxes_of_crackers): print "You have %d cheeses!" % cheese_count print "You have %d boxes of crackers!" % boxes...
阅读全文
浙公网安备 33010602011771号