Python List Manipulation Techniques

lists in python n.w
1 / 4
Embed
Share

Learn about simple ways to create lists in Python using hard-coded values, replication operator, string split method, file readlines method, and more. Explore the differences between append and concatenate methods for adding elements to lists, and how to accumulate lists using concatenation or append techniques.

  • Python Lists
  • List Manipulation
  • Append vs Concatenate
  • Python Programming

Uploaded on | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Lists in Python Creating lists

  2. Simple ways to create a list Hard code the values mylist = [3, 9, a , 7.2] Using the replication operator mylist = [0] * 100 (gives a list with 100 zeros) Use the split method on a string Use the readlines method on a file Put [] around a variable if my_num is 5, then [ my_num] is the list [5]

  3. Append vs. Concatenate Both can be used to add to an existing list but their syntax is not the same The concatenate operator + uses two lists and creates a bigger one You cannot say mylist = mylist + joe , it must be mylist = mylist + [ joe ] Append is a method which adds an element to the right end of a list any type of data mylist.append( 3 ) makes mylist one element longer

  4. List accumulation Either concatenation or append can be used with lists as accumulators Initialize the list variable as an empty list [] inside your loop either concatenate or append the new item onto your list variable

More Related Content