源代码如下:

 1 #coding:utf-8
 2 
 3 print "Let's practice everything."
 4 print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
 5 # 各种转义
 6 poem = """
 7 \tThe lovely world
 8 with logic so firmly planted
 9 cannot discern \n the needs of love 
10 nor comprehend passion from intuition
11 and requires an explanation
12 \n\t\twhere there is none.
13 """
14 # 制表符
15 # 换行符
16 
17 print "--------------"
18 print poem
19 print "--------------"
20 
21 five = 10 - 2 + 3 - 6
22 print "This should be five: %s" % five
23 
24 def secret_formula(started):
25     jelly_beans = started * 500
26     jars = jelly_beans / 1000
27     crates = jars / 100
28     return jelly_beans, jars, crates
29 # 结果返回函数
30 start_point = 10000
31 beans, jars, crates = secret_formula(start_point) 
32 # beans,jars,crates可以换成任意变量名
33 print "with a starting point of: %d" % start_point
34 print "We'd have %d beans, %d jars, and %d crates." % (beans, jars, crates) 
35 # 变量名也需要相应变更
36 start_point = start_point / 10
37 
38 print "We can also do that this way:"
39 print "We'd have %d beans, %d jars, and %d crates." % secret_formula(start_point)

 

输出结果:

 

posted on 2017-10-11 17:29  讲道理好嘛  阅读(262)  评论(0编辑  收藏  举报