need help with python.. please paste ur working and indented code here   Write one line of code for each of the following: 1) Create a list named fruits with the following items: "apple", "cherry", "pear" 2) Add "orange" at the end of the fruits list. 3) Change the value from "cherry" to "banana", in the fruits list. 4) Use the insert method to add "lemon" as the third item in the fruits list. 5) Use slicing to print the third, fourth, and fifth items in the current fruits list. 6) Use the del function to remove "banana" from the current fruits list. 7) Use negative indexing to print "pear" in the current fruits list.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

need help with python.. please paste ur working and indented code here

 

Write one line of code for each of the following:

1) Create a list named fruits with the following items:
"apple", "cherry", "pear"

2) Add "orange" at the end of the fruits list.

3) Change the value from "cherry" to "banana", in the fruits list.

4) Use the insert method to add "lemon" as the third item in the fruits list.

5) Use slicing to print the third, fourth, and fifth items in the current fruits list.

6) Use the del function to remove "banana" from the current fruits list.

7) Use negative indexing to print "pear" in the current fruits list.

Expert Solution
Step 1

List: To storing multiple items in a single variable we can use a list, we can also say it is one type of array but the list has no particular data type so we can store any mixed data into it.

Synatx:

varibale_name = [element1, element2, ...]

 

Adding Item to list:

We can use multiple ways to add items to the list.

  • By using append() method:

append() method: append method is used to add an item or element to the end of the list.

Syntax:

list_name.append(element)

 

  • By using insert() method:

insert() method: insert method is used to add an item or element to the specific index of the list.

Syntax:

list_name.insert(index, element)

 

Slicing list:

we can slice the list by using the slice() method.

Syntax:

list_name[initial: End: number_of_index_jump]

 

deleting element from the list:

we can delete elements at a particular index from the list using the del keyword.

Syntax of del for list:

del list_name[index]

 

we can also remove elements from a list by the value of the element itself using the remove() method.

Syntax:

list_name.remove(element_value)
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY