如何在Python中删除整数中的.0

Rob*_*Rob 5 python python-2.7

我想删除.0计算这些时间的时间。

current_time = datetime.timedelta(hours = 22, minutes = 30)
program_end = datetime.timedelta(hours = 23, minutes = 40)
program_duration = program_end - current_time
program_widths = int(program_duration.seconds / 60)
program_widths = program_widths * 11.4
Run Code Online (Sandbox Code Playgroud)

输出:

794.0
Run Code Online (Sandbox Code Playgroud)

结果

>>>> 794
Run Code Online (Sandbox Code Playgroud)

你能帮我如何删除.0我使用的整数吗?

ᴀʀᴍ*_*ᴍᴀɴ 6

使用int函数将您的float号码转换为int

int(794.0) # 794
Run Code Online (Sandbox Code Playgroud)

在你的程序中,program_widths = int(program_widths)如果你希望你的变量变成,int如果你想将它打印为只是int转换为 int 进行打印,请尝试这个 ->print int(program_widths)