练习24:代码巩固练习
来源:互联网 发布:医保网络业务申请表 编辑:程序博客网 时间:2024/05/17 22:52
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 plantedcannot discern \n the needs of lovenor comprehend passion from intuitionand requires an explantion\n\t\twhere there is none."""print "--------------"print poemprint "--------------"five = 10 - 2 + 3 - 6print "This should be five: %s" % fivedef secret_formula(started): jelly_beans = started * 500 jars = jelly_beans / 1000 crates = jars / 100 return jelly_beans, jars, cratesstart_point = 10000beans, jars, crates = secret_formula(start_point)print "With a starting point of: %d" % start_pointprint "We'd have %d beans, %d jars, and %d crates." % (beans, jars, crates)start_point = start_point / 10print "We can also do that this way:"print "We'd have %d beans, %d jars, and %d crates." % secret_formula(start_point)
这里涉及到一些原来没见过的代码句式
beans, jars, crates = secret_formula(start_point)
如上行代码,当函数有多个返回值,可以在等号左边用逗号分隔的方式写上多个变量(与函数返回值数目一致),返回值会依次赋值给各个变量(就和解包argv时用的方法差不多)
print "We'd have %d beans, %d jars, and %d crates." % secret_formula(start_point)
如上行代码,可以直接用格式化字符输出函数的返回值,格式化字符数目和类型应该符合函数返回值数目和类型
0 0
- 练习24:代码巩固练习
- 练习巩固知识点
- 巩固练习3
- struts2练习及巩固
- 【HTML】小练习,复习巩固
- java基础巩固练习(二)
- javaee之hibernate的加强巩固练习
- HTML巩固练习之列表的使用
- HTML巩固练习之表格的使用
- HTML巩固练习之超链接的使用
- HTML巩固练习之CSS基础
- HTML巩固练习之CSS选择器基础
- HTML巩固练习之字体样式
- 代码练习
- 代码练习
- 练习代码
- 代码练习
- 代码练习
- C语言指针实现循环报数问题(简单约瑟夫环问题)
- 【转】MySQL 5.6 for Windows 解压缩版配置安装
- URAL 1841|Cableways|...
- 结构化思维(Structured Thinking)
- BlockingQueue
- 练习24:代码巩固练习
- 关于IGMP协议的知识点汇总
- jQuery中.bind() .live() .delegate() .on()的区别
- JAVA字符串格式化-String.format()的使用
- poj3249【拓扑排序】
- 从嵌入式linux到android应用开发
- HDU 1002 Strange fuction
- C++第4作业
- Linux 网络层实现