CSE 163
Introduction to Python II
Strings and Lists
Hunter Schafer
πΆ Listening to: Carly Rae Jepsen
π¬ In Zoom Chat: Tea or coffee? Other?
This Time
Last Time
2
Questions during Class
Feel free to ask questions in Zoom chat, someone can respond in chat or Hunter might answer the question while talking. Donβt feel pressured to read messages, we will point out anything important for everyone to hear.
TAs and I will be hanging out in chat before/after class and can answer questions or just chat if you want to hang out!
If we miss your question in chat, feel free to ask after class or post on EdStem so we can answer later!
During breakouts, please use chat if you donβt have a mic!
3
Recap: Lesson
Strings
Lists
Documentation
None
4
String Methods vs. len
Call functions on strings using syntax:
This is not true for len (or other built-in Python functions):
This asymmetry is annoying, but you have to get used to it!
5
s.function(params)
len(s)
Strings
vs.
Lists
6
s = 'hello world'
# Length
len(s) # 11
# Indexing
s[1] # 'e'
s[len(s) - 1] # 'd'
# Looping
for i in range(len(s)):
print(s[i])
for c in s:
print(c)
l = ['dog', 'says', 'woof']
# Length
len(l) # 3
# Indexing
l[1] # 'says'
l[len(l) - 1] # 'woof'
# Looping
for i in range(len(l)):
print(l[i])
for word in l:
print(word)
None
7
def increment(x):
if x < 0:
return None
else:
return x + 1
if increment(-1) is None:
print('Failed')
Group Work: Mechanics
Group work will be done in Zoom breakouts
Will automatically move you to breakout rooms and bring you back when we want to debrief.
8
Group Work:
Best Practices
When you first working with this group:
Tips:
9