Python: Define a function that takes a list of many points

时间:2017-11-12 22:32:28

标签: python python-3.x function parameters computer-science

When I write my function like this, it works perfectly:

a = [(9,0), (6,6), (1,15), (243, 635), (9, 7), (7,8), (2,4)]
def func(a)
   #function calculation
return Min dist

But this function is not very feasible since it will only calculate the given ‘a’ within the code. Is there a way to make the function recognize ‘a’ as a list containing however many points the user inputs? For example, I want the function to work like this:

def func(a)
   #calculation
return Min dist

In console:

[In:] a = [(9,0), (6,6), (1,15), (243, 635), (9, 7), (7,8), (2,4)]
[O:] 3.436788

1 个答案:

答案 0 :(得分:1)

是的,你已经可以:

您的模块

def func(a)
    #function calculation
    return Min dist

你的主要

a = [(9,0), (6,6), (1,15), (243, 635), (9, 7), (7,8), (2,4)]
b = [(9,0), (6,6), (1,15), (243, 635), (9, 7), (7,8), (2,4)]
c = [(9,0), (6,6), (1,15), (243, 635), (9, 7), (7,8), (2,4)]
func(a)
func(b)
func(c)