PythonSequences - Python Sequences Strings, Lists, and...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Python Sequences Strings, Lists, and Files 1 © Popescu 2012
Background image of page 1

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

View Full DocumentRight Arrow Icon
Reading: Chapter 5 from Zelle text 2
Background image of page 2
Strings String data type 1-D array o characters Text in between quotation marks E.g. “valid string” Simple quotation also accepted, i.e. ‘valid string’ 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
String operations Input The input() built in function E.g. name = input(“Input your name: “ ) Output The print() built in function E.g. print(name) Indexing Access to any character using integer index Indexing from right using negative indices Indexing returns a string with a single character 4
Background image of page 4
String operations 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
String operations Slicing Defines substrings within string Consider a string variable called sentence 'CS 17700 is offered in spring 2012' sentence[0:3] is ‘CS ‘ sentence[9:] is 'is offered in spring 2012‘ sentence[:8] is ‘CS 17700’ Concatenation ‘123’ + ‘456’ = ‘123456’ Repetition ‘123’*3 = ‘123123123’ 6
Background image of page 6
7
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/27/2012 for the course CS 177 taught by Professor Staff during the Spring '08 term at Purdue University-West Lafayette.

Page1 / 16

PythonSequences - Python Sequences Strings, Lists, and...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online