time = raw_input()
if "PM" in time:
ls = time.split(":")
int(ls[0])
print type(ls[0])
I have a problem on Hackerearth which I was solving. But my code here doesn't change the str to int. The output is
<type 'str'>
I want to change the first element of the time to int so i can perform mathematical calculations on it. Input it takes is
6:05:08PM
int()
returns the integer. The variable is not changed in-place.
Assign the result:
ls[0] = int(ls[0])
Integer = int(ls[0])
它将str转换为一个int,然后您可以使用此Integer进行计算
int(ls[0])
应该可以解决问题,但是请注意,这是一种不太安全的方法。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.