【问题标题】:How to reference the global variables within another function in python如何在python中的另一个函数中引用全局变量
【发布时间】:2022-08-02 11:46:14
【问题描述】:

标签: python-3.x function loops


【解决方案1】:

如果我的直觉是正确的,那么您要做的就是将列表的值放入您刚刚定义的函数中。如果是这种情况,请使用以下命令:

l1 = [10,20,30,40,50]
l2 = [10,30,40,50,10]

def fun_1(list1):
    if(list1[0] == list1[4]):
        print("both are same")
    else:
        print("both are not same")

def fun_2(list2):
    if(list2[0] == list2[4]):
        print("both are same")
    else:
        print("both are not same")
    
fun_1(l1)
fun_2(l2)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-16
    • 1970-01-01
    相关资源
    最近更新 更多