[英]Type casting at once python
How can I do this better? 我该如何做得更好?
#! /usr/bin/python
text = "50:0.0"
(string, floating) = text.split(':')
floating = float(floating)
Particularly the casting part of it. 特别是铸件。 Is it possible to include casting part within the second line of the code? 是否可以在代码的第二行中包含强制转换部分?
没有比您已经拥有的方法更简单的方法:
string, floating = (lambda (x, y): (x, float(y)))(text.split(':'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.