1

Suppose I have a list [1,2,3,4,5]. Now I want to pass the elements of this list, starting from 3rd element to a method.

i.e. i want to invoke:

myfunction([3,4,5])

How can I do this in python. tried passing mylist[2], but it doesn't quite work this way it seems.

nish
  • 6,952
  • 18
  • 74
  • 128

1 Answers1

6

slicing.

mylist = range(1,6)
>> [1,2,3,4,5]
myfunction(mylist[2:])
>> [3,4,5]
Community
  • 1
  • 1
Bruno Gelb
  • 5,322
  • 8
  • 35
  • 50