CECS 174 Lecture 5: Strings

98 views7 pages

Document Summary

# a string is a sequence of characters of some length. # a "sequence" is a bunch of individual things in a row, # len(_): returns the length of a given string value. print(len(name)) # brackets can be used to read an individual character from a. An index is a position within a string, with. # the first character being index 0. print(name[1]) # access an individual character of the string. # python is unusual: it allows negative indexes, which count from. # the right end instead of the left. print(name[-1]) # although we can access at an index, we can"t modify at an index. # strings can be compared with == and !=. if name == "neal": print("hi, neal!") else: print("i don"t know who you are!") # individual characters can be compared, too. other_name = "neil" if other_name[2] == "i": print("you spell your name wrong,", other_name, "!") # we can use a loop to iterate over each individual.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions