Lists in Python.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Chapter 6 Lists and Dictionaries CSC1310 Fall 2009.
1 Arrays Chapter 9. 2 Outline  The array structure (Section 9.1)  Array declaration  Array initialization  Array subscripts  Sequential access to.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
JaySummet IPRE Python Review 2. 2 Outline Compound Data Types: Strings, Tuples, Lists & Dictionaries Immutable types: Strings Tuples Accessing.
CMPT 120 Lists and Strings Summer 2012 Instructor: Hassan Khosravi.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Guide to Programming with Python
Lilian Blot CORE ELEMENTS COLLECTIONS & REPETITION Lecture 4 Autumn 2014 TPOP 1.
COMPUTER SCIENCE FEBRUARY 2011 Lists in Python. Introduction to Lists Lists (aka arrays): an ordered set of elements  A compound data type, like strings.
October 4, 2005ICP: Chapter 4: For Loops, Strings, and Tuples 1 Introduction to Computer Programming Chapter 4: For Loops, Strings, and Tuples Michael.
Lists in Python.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
Fundamentals of Python: First Programs
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 8 Working.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
Strings The Basics. Strings a collection data type can refer to a string variable as one variable or as many different components (characters) string.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 10 Lists 1.
Lists vs Strings CMSC 201. Overview Python strings and lists are similar but different. Similar: syntax, access mechanisms, operators Different: Strings.
Python Programing: An Introduction to Computer Science
Python Arithmetic Operators OperatorOperationDescription +AdditionAdd values on either side of the operator -SubtractionSubtract right hand operand from.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Guide to Programming with Python Chapter Four Strings, and Tuples; for Loops: The Word Jumble Game.
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
String and Lists Dr. José M. Reyes Álamo.
Using Molecular Biology to Teach Computer Science
Topic: Python Lists – Part 1
Sequences and Indexing
Computer Programming BCT 1113
Chapter 10 Lists.
Lecture 10 Data Collections
2. Understanding VB Variables
Strings Part 1 Taken from notes by Dr. Neil Moore
Introduction to Python
Lists Part 1 Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Visual Basic .NET BASICS
Introduction to Strings
Introduction to Strings
Introduction to Python
Set-Builder Notation.
Chapter 10 Lists.
CEV208 Computer Programming
Lists A list is an ordered set of values, where each value is identified by an index. The values that make up a list are called its elements. Lists are.
String and Lists Dr. José M. Reyes Álamo.
MSIS 655 Advanced Business Applications Programming
Topics Sequences Introduction to Lists List Slicing
Lists Part 1 Taken from notes by Dr. Neil Moore
Arrays Week 2.
Introduction to Strings
CISC181 Introduction to Computer Science Dr
CS150 Introduction to Computer Science 1
CS1110 Today: collections.
15-110: Principles of Computing
JavaScript: Arrays.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CISC101 Reminders Assignment 2 due today.
Topics Basic String Operations String Slicing
CHAPTER 4: Lists, Tuples and Dictionaries
Topics Sequences Introduction to Lists List Slicing
And now for something completely different . . .
Introduction to Strings
Python Review
Topics Basic String Operations String Slicing
Class code for pythonroom.com cchsp2cs
Introduction to Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Enclosing delimiters Python uses three style of special enclosing delimiters. These are what the Python documentation calls them: {} braces # Sometimes.
Strings Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Topics Basic String Operations String Slicing
Presentation transcript:

Lists in Python

Lists = arrays A list is a sequential collection of values, it is a data structure Each value has a location (an index) Indexes range from 0 to n-1 (where n is the length of the list) and from -1 to -n Lists are heterogeneous = values can be of any type (strings are homogeneous because their elements are characters)

List syntax Values are enclosed in [], myList = [3, ‘a’, True] One list can contain another Empty list = [] Any type of data can be in the list You usually refer to a list by elements, that is with the []. You can refer to a list by its name (as one whole thing) when passing it as an argument to a function.

List semantics Lists are mutable, that is, elements can be changed Individual elements can be changed the same way any variable can be changed, with an assignment statement myList = [1,9, ‘a’, 4, 7] m = 3 myList[m] = 99 myList[m+1] = 88

Length function The same as with the string type, len (lst) will return an integer, the number of elements in the list, from zero up to some max int value If a list contains a sublist, it counts as one element L = [1, [3, 4], 7] has 3 elements You call it as part of another statement, for example, print(len(mylist))

Accessing elements of a list The index starts at 0 just like with a string and goes up to n-1 if there are n elements in the list They also can use negative subscripts, -1 is the last element on the right, -n on the left end