4-1. Sequences - 4 SEQUENCES STRINGS LISTS AND FILES(PART I...

Info icon This preview shows pages 1–6. Sign up to view the full content.

4. SEQUENCES: STRINGS, LISTS AND FILES (PART I) Rocky K. C. Chang September 15, 2015 (Adapted from John Zelle’s slides)
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Objectives To understand the string data type and how strings are represented in the computer. To be familiar with various operations that can be performed on strings through built-in functions and the string library. To understand the basic idea of sequences and indexing as they apply to Python strings and lists.
Image of page 2
The String Data Type Text is represented in programs by the string data type. A string is a sequence of characters enclosed within quotation marks (") or apostrophes ('). >>> str1="Hello" >>> str2='spam' >>> print(str1, str2) Hello spam >>> type(str1) <type 'str'> >>> type(str2) <type 'str'>
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

EXERCISE 4.1 o Create a string str = “Hello World!”. o Enter str[0], str[5], str[11], str[12], and find out what you are doing.
Image of page 4
Indexing a string A string is a sequence of characters. The first character is indexed by 0, the second by 1, and so on.
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Image of page 6
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '16
  • Rocky Chiang
  • ASCII, Formal language, len, Sausage

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern