重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
def calc(average):
公司主营业务:网站设计制作、网站设计、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联建站是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联建站推出措勤免费做网站回馈大家。
sum=0
for i in average:
sum+=i
return (sum/3)
print(calc([1,2,3]))
代码解释如下:
input_file作为变量,指的是一个文件的路径;
current_file = open(input_file)这一句获取input_file的内容,这时候current_file 相当于f;
print_all (current_file)就是用current_file调用了print_all 函数,此时f=current_file;
此时,解决了提问者的第一个疑问。
def是定义函数的一个声明语句,语法结构如下:
def FunctionName(para1,para2):
print "创建示例"
所以:
def print_all(f):
print f.read()定义了一个print_all的函数,该函数有一个变量称作f;
print f.read()是这个函数的执行语句;
简单来说
str()将数值转成字符串
repr()将对象转成字符串显示,注意只是显示,有些对象转成字符串没有意义。如list,dict使用str()是无效的,但使用repr可以,这是为了显示他们的值
以下内容摘自google
The str() function is meant to return representations of values which are fairly
human-readable, while repr() is meant to generate representations which can be read by the interpreter (or will force a SyntaxError if there is not equivalent syntax). For
objects which don't have a particular representation for human consumption, str() will
return the same value as repr(). Many values, such as numbers or structures like lists
and dictionaries, have the same representation using either function. Strings and
floating point numbers, in particular, have two distinct representations.
Some examples:
s = 'Hello, world.'
str(s)
'Hello, world.'
repr(s)
"'Hello, world.'"
str(0.1)
'0.1'
repr(0.1)
'0.10000000000000001'
x = 10 * 3.25
y = 200 * 200
s = 'The value of x is ' + repr(x) + ', and y is ' + repr(y) + '...'
print s
The value of x is 32.5, and y is 40000...
# The repr() of a string adds string quotes and backslashes:
hello = 'hello, world\n'
hellos = repr(hello)
print hellos
'hello, world\n'
# The argument to repr() may be any Python object:
repr((x, y, ('spam', 'eggs')))
"(32.5, 40000, ('spam', 'eggs'))"
# reverse quotes are convenient in interactive sessions:
`x, y, ('spam', 'eggs')`
"(32.5, 40000, ('spam', 'eggs'))"