670
备注:
|
1568
|
删除的内容标记成这样。 | 加入的内容标记成这样。 |
行号 30: | 行号 30: |
wordscounter.py {{{#!python words = {} try: while True: s = raw_input() if not s: continue if s in words: words[s]+=1 else: words[s]=1 except EOFError: for i in sorted(words.keys()): print "%s %d" % (i, words[i]) }}} test.py {{{#!python class Person: def __getitem__(self, key): return key p = Person() s = Person() Person.name = "Unknown" p.name = "Jack" p.gender = "Male" p.age = 30 s.name = "Rose" s.gender = "Female" print Person print p print s print Person.name print p.name print p.gender print p.age print s.name print s.gender print s[0] }}} multiply99.py {{{#!python def multi99(n): for i in range(1,n+1): s = '' for j in range(1,i+1): s += '\t%d'% (i*j) print s multi99(20) }}} |
test.py
test2.py
wordscounter.py
test.py
1 class Person:
2 def __getitem__(self, key):
3 return key
4
5
6 p = Person()
7 s = Person()
8
9 Person.name = "Unknown"
10 p.name = "Jack"
11 p.gender = "Male"
12 p.age = 30
13 s.name = "Rose"
14 s.gender = "Female"
15
16 print Person
17 print p
18 print s
19 print Person.name
20 print p.name
21 print p.gender
22 print p.age
23 print s.name
24 print s.gender
25
26 print s[0]
multiply99.py