CSC108H1 Lecture Notes - Empty String, Substring

36 views2 pages
11 Jan 2013
School
Course
yifanyang and 39659 others unlocked
CSC108H1 Full Course Notes
21
CSC108H1 Full Course Notes
Verified Note
21 documents

Document Summary

String comparison: you can use the comparison operators on strings, the comparison will be made alphabetically, an ordering is defined even for non-alphabetic characters, ex. Indexing strings: s[1], 1 = integer: allows you to extract a single character, the first character is at index 0, a negative index means to count backwards from the end, always return a new object. Slicing strings: s[left:right: allows you to extract a substring in one step, always returns a new object, the lower bound is inclusive, but the upper bound is not, if omitted, left defaults to 0, right to len(s) >>> s[3] = x # operation not allowed, string immutable. >>> print s, , s2 llo hello. Call methods using the same notation as calling a function in a module: Calling methods: because you provide the string using dot notation, you don"t need to pass it as an argument: Villain. capitalize(villain) # redundant: a method may have parameters if it needs additional information:

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions