SlideServe
Menu
Préférences
© SlideServe · v2026

Lists and Strings

piera avatar
16 diapositives · 490 Views · Jul 24, 2014

Lists and Strings. George Mason University. Today’s topics. Review of Chapter 5 : Lists and Strings Go over examples and questions lists and strings in Python. List (and strings) review. How do we declare a list? An empty list? What operations can we apply to lists?

Lists and Strings - slide 1
01 / 16Lists and Strings
1 / 17

Télécharger la présentation

Lists and Strings
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Lists and Strings George Mason University

  2. Today’s topics • Review of Chapter 5: Lists and Strings • Go over examples and questions • lists and strings in Python

  3. List (and strings) review • How do we declare a list? An empty list? • What operations can we apply to lists? • How are lists represented in memory? • primitive types • complex types • What happens when we assign a variable to a list? (in memory) • What is a character? • How is a string similar to a list? Different? • What is the substring operation?

  4. Let’s go over the exercises

  5. Lists in python • .append( )is a way to add a single element to the end of a list

  6. length in python • len( ) is a function to return the length of a list or string

  7. python memory visualizer • let’s use the python memory visualizer to trace through an example: http://pythontutor.com/visualize.html#code=x+%3D+1%0Asmall+%3D+%5Bx,+2,+3%5D%0Amedium+%3D+%5B43,+76,+180,+57%5D%0Alarge+%3D+%5B234%5D%0AbigList+%3D+%5Bmedium,+small,+large%5D%0Aprint+small%0Aprint+bigList%0Asmall%5B0%5D+%3D+-1%0Aprint+small%0Aprint+bigList%0Ax+%3D+7%0Aprint+small&mode=display&cumulative=false&heapPrimitives=false&drawParentPointers=false&textReferences=false&showOnlyOutputs=false&py=2&rawInputLstJSON=%5B%5D&curInstr=0 Note the difference between the storage of x, a primitive, and the lists.

  8. Debugging with id( ) • id( ) can be used to print out the memory address of a complex type • str( ) is needed to add non-strings to strings

  9. Debugging with id( )

  10. index( ) • Note you’ll need to check if the element is in the list or string before trying to get its index

  11. in • in is a keyword and can be used to check if the element is in the list or string before trying to get its index

  12. substrings and sub-lists with [:]

  13. newlines and tabs

  14. Other useful functions • min(list) • max(list) • list.remove(1.5) • sortedList = sorted(list)

  15. Strings in Python • ‘cat’ and “cat” are the same • can use single or double quote • default is single quote • useful for “’” versus ‘”’

  16. Questions?