[英]Python: repeat function with different arguments in a single expression
I love being able to assign and use multiple variables in a single expression - it looks particularly elegant. 我喜欢能够在一个表达式中分配和使用多个变量 - 它看起来特别优雅。 How can I repeat any arbitrary function and have my code behave as expected without using a loop?
如何在不使用循环的情况下重复任何任意函数并使我的代码按预期运行? To demonstrate the integer conversion below should only use a single line.
要演示下面的整数转换,应该只使用一行。
string = '75 45 120'
v0,v1,v2 = string.split()
v0 = int(v0)
v1 = int(v1)
v2 = int(v2)
print(v0,v1,v2,v1+v2,sep=', ') # 75, 45, 120, 165
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.