Respuesta :

Answer:

def swap(li):

   n=len(li)

   li[0],li[n-1]=li[n-1],li[0]

   return li

Explanation:

Python is very user friendly language and and this provides numerous functions and in-built services. In the above function, i have created a method which is taking an argument li and we can find the length of li by using method len() which is then stored in variable n. Now we have to swap first and last element so, first element of li is li[0] and last is li[n-1]. Python provides one more utility in which we can change values of 2 elements simultaneously by separating them with comma. So, we put the value of last element in first and value of first in last which saved many lines of code.

The program illustrates the use of lists in Python.

The required function is as follows, where comments are used to explain each line

#This defines the function;

def swap(myList):

   #This swaps the first and last elements of the list

   myList[0],myList[-1]=myList[-1],myList[0]

   #This returns the list to the main function

   return myList

At the end of the function, the first and last elements of the list are swapped and returned to the main function.

See attachment for sample run

Read more about Python lists at:

https://brainly.com/question/21030874

Ver imagen MrRoyal