ECS 32A Lecture 6: Strings and Lists

64 views2 pages
19 Jan 2019
School
Course
Professor
1/18/19
Using the math module
Import math
math.sqrt(16)
The math module has tons of useful math functions
math.ceil(my_num)
Representing Text
Unicode table
Letters are in decimal order from first to last, but uppercase comes before
lowercase, and there could be characters in-between
Avoid doing manual encoding/decoding
Escape characters
\ is a special characters called an espace character
Printing a backslash
“\\”
Print a new line
“\n”
Print a tab
“\t”
String
Sequence of characters: A Python sequence is an in-order collection
len() function returns the length of a given string
String Indexing
Read [0] as at location 0”
My_string = Renaissance”
print(my_string[0]) #0 is the first char
print(my_string[500]) # Failure
String Concatenation and Repetition
my_string = every + thing”
my_string *= 3
List
Containers: group related values together
a sequence of indexed elements
List syntax:
my_list = [bears, beets]
print(my_list[0]) # prints the first element
Lists are Mutable
You can add elements or remove elements to the list without creating new
objects
Methods to do that
append()
Adds it to the end
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+
$10 USD/m
Billed $120 USD annually
Homework Help
Class Notes
Textbook Notes
40 Verified Answers
Study Guides
1 Booster Class
Class+
$8 USD/m
Billed $96 USD annually
Homework Help
Class Notes
Textbook Notes
30 Verified Answers
Study Guides
1 Booster Class