练习24--更多练习
Posted luoxun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了练习24--更多练习相关的知识,希望对你有一定的参考价值。
一 复习内容
1 转义字符 : ‘ \
2 format格式化函数 ——三种不同的打印方法
- "{}".format(变量名)
- f"{变量名}"
- "{}{}{}".format(*元组)
3 三引号的使用:程序头部或者尾部用来做注释,代码中间使用并将其赋给一个变量——即文档字符串
4 算术运算符 + - * /
5 定义函数并设置返回值 def
6 函数调用 函数名(参数)
二 代码及运算结果
1 ex24.py文件
print("Let‘s practice everthing.") # 打印一些提示信息 print(‘You‘d need to know ‘bout escapes with \ that do:‘) print(‘ newlines and tabs.‘) # 用三引号定义一首诗 poem = """ The lovely world with logic so firmly planted cannot discern the needs of love nor comprehend passion from intuition and requires an explanation where there is none """ # 将诗句的内容打印出来 print("----------------------------------") print(poem) print("----------------------------------") # 完成数学运算 five = 10 - 2 + 3 - 6 print(f"This should be five:{five}") # 定义一个secret_formula函数,并返回三个变量的值 def secret_formula(started): jelly_beans = started * 500 jars = jelly_beans / 1000 crates = jars / 100 return jelly_beans,jars,crates # 调用secret_formula函数,并将其函数返回值分别赋给beans,jars,crates start_point = 10000 beans,jars,crates = secret_formula(start_point) # 使用三种不同的format格式化函数输出方法 # remember that this is another way to format a string print("With a starting point of: {}".format(start_point)) # "{}".format(变量名) # is‘s just like with an f"" string print(f"We have {beans} beans,{jars} jars, and {crates}crates.") # f"{变量名}" start_point = start_point / 10 print("We can also do that this way:") formula = secret_formula(start_point) print(type(formula)) # this is an easy way to apply a list to a format string print("W‘d have {}beans,{}jars,and {} crates.".format(*formula)) #"{}{}{}".format(*元组)
2 运行结果
PS E:3_work4_python2_code_python 2_LearnPythonTheHardWay> python ex24.py Let‘s practice everthing. You‘d need to know ‘bout escapes with that do: newlines and tabs. ---------------------------------- The lovely world with logic so firmly planted cannot discern the needs of love nor comprehend passion from intuition and requires an explanation where there is none ---------------------------------- This should be five:5 With a starting point of: 10000 We have 5000000 beans,5000.0 jars, and 50.0crates. We can also do that this way: <class ‘tuple‘> W‘d have 500000.0beans,500.0jars,and 5.0 crates.
以上是关于练习24--更多练习的主要内容,如果未能解决你的问题,请参考以下文章
spring练习,在Eclipse搭建的Spring开发环境中,使用set注入方式,实现对象的依赖关系,通过ClassPathXmlApplicationContext实体类获取Bean对象(代码片段
Python练习册 第 0013 题: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-),(http://tieba.baidu.com/p/2166231880)(代码片段