可变的存储空间多于直接数字
def add(a,b):
print(a+b)
#method 1
add(2,3)
#method 2
a = 2
b = 3
add(a,b)
#在这两种方法中使用的方法较少,请告诉
def add(a,b):
print(a+b)
#method 1
add(2,3)
#method 2
a = 2
b = 3
add(a,b)
#in these two methods which method take less storage please tell
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用第二种方法时,您会声明两个变量
a
和b
在函数调用中,该函数调用在内存中占据空间。同时,在第一个中,您只是调用add()
函数而不创建更多变量或占用内存空间,这是因为您直接分配了没有外部数据存储的函数参数的值。When using the second method, you declare two variables
a
andb
before the function call that takes space in memory. Meanwhile, in the first one, you are just invoking theadd()
function without creating any more variables or occupying memory space, that's because you are directly assigning the values of the function arguments without external data storage.