[SOLVED] Accepting an array with n elements in a function – Python

Issue

Is there a way in which I can set a function to accept an array with a certain number of elements as a parameter?

I am wondering whether this is possible in the parameter section itself and not through some sort of validation.

Solution

I do not believe this would be possible in Python to my knowledge,
this may not be what you want but this might work:

def foo(array, array_length):
  if array_length != len(array):
    return

  # function code

Answered By – dean0x45

Answer Checked By – Candace Johnson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *