[英](Python) How can I split a column with both date and time (e.g. 2019-07-02 00:12:32 UTC) into two separate columns?
[英]How can I separate a double digit to two single digits with python? e.g. 15 -> 1, 5
def plus_cycles():
n = int(input("Write here the number that you want. (1~99)\n"))
while True:
if n < 10:
a = "n" + "0"
在这段代码中,我希望 a 用两个个位数分隔。 例如 15 -> 1, 5 或 [1, 5]
divmod()
方法接受两个数字并返回一对数字(一个元组),由它们的商和余数组成。 对于整数,结果与(a // b, a % b)
相同。
>>>> divmod(15, 10)
(1, 5)
>>> 15 // 10
1
>>> 15 % 10
5
你可以这样做:
>>> intToList = lambda number : [int(i) for i in list(str(number))]
>>> intToList(15)
[1, 5]
list(str(15))
将返回一个字符列表,例如:
>>> list(str(15))
['1', '5']
所以我们用一个 for 循环遍历它们,把它们变成整数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.