[英]In python, how do you accept integers as parameters?
How do you write a function that accepts integers as parameters?你如何编写一个接受整数作为参数的函数?
I haven't tried anything yet because I have no idea where to start.我还没有尝试任何东西,因为我不知道从哪里开始。
the way you define any function:你定义任何函数的方式:
def f(x):
'''
square x
'''
return x**2
print(f(4))
def myfunction(myint):
print("this is an integer " + str(myint))
myfunction(4)
Python keeps track of the types of variables without having to explicitly state the type. Python 会跟踪变量的类型,而无需显式声明类型。
https://wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language https://wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language
That being said you can use type hints in Python 3:话虽如此,您可以在 Python 3 中使用类型提示:
def f(x: int):
return x ** 2
In my opinion they are fantastic.在我看来,他们太棒了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.