[英](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.