如何在python中转换为int?
我的名字是Jay,我是python和编码新手 如何将结果转换为整数如何在python中转换为int?,python,Python,我的名字是Jay,我是python和编码新手 如何将结果转换为整数 # This function adds two numbers def add(x, y): return x + y # This function subtracts two numbers def subtract(x, y): return x - y # This function multiplies two numbers def multiply(x, y): return x *
# This function adds two numbers
def add(x, y):
return x + y
# This function subtracts two numbers
def subtract(x, y):
return x - y
# This function multiplies two numbers
def multiply(x, y):
return x * y
# This function divides two numbers
def divide(x, y):
return x / y```
How can I go on?
要转换为整数,必须使用
int(x)
像这样:
def my_function(x,y):
return int(x / y)
您可以使用
int()
并在其中输入任何数字。这是否回答了您的问题?这回答了你的问题吗?请注意,int(3.9)
给出了3
。换句话说,int()
截断数字的小数部分。在转换之前将0.5
添加到您的数字将使舍入行为更直观(但我认为并不总是正确)。这是一个重复,可以在文档中轻松查找