我如何将特定参数设置为python的功能,就像c
请如何指定所需的函数和参数类型的返回值,例如在C中,我们声明了这样的原型函数,然后键入它需要:
int *atoi(char *str)
please how can I specify the return values of a function and types of arguments it required , like in C we declare a prototype function like this and type it requires :
int *atoi(char *str)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将其用于参数和变量。但是问题在于,分配时可以随时更改此类型。
但这也将在不增加错误的情况下起作用
,让我们获得函数参数
以上函数将以第一个参数为第一个参数,将字符串作为第二个参数,并将输出字符串。
但是没有像C或Java这样的违约。这样的参数必须仅在指定的数据类型中。输出数据类型也是如此。
You can use this for both arguments and variables. But the problem is the this type can be changed at any time when assigning.
but this also will work without raising error
and lets get function arguments
The above function will take an integer as first argument , string as the second one and will output a string.
But there is no contrains like C or java. Such like arguments must be in the specified data type only. The same is for the output data type also.
不幸的是,在Python中,没有确定的约束方式。即,您可以编写这样的代码:
如果要在代码上设置约束,我建议设置
try/deve/exce
子句,该条款试图转换为正确的类型不起作用。像这样:Unfortunately, in python there's no definitive ways of constraining. I.e. you can write code like this:
If you want to set constraints on code, I would suggest setting up a
try/except
clause which tries to convert to the correct type, and raises an error if it does not work. Like so: