### Lecture Materials

Q: is there a recording of the pixar talk yesterday?

A1:  Yep, it’s on canvas

Q: Is Alan Turing the person that the Turing award is named after?

A1:  Yes!

Q: is this what the infamous heap allocator is?

A1:  The heap allocator basically finds a spot in your computer’s memory for a variable

Q: How are they stored? (like in URL)

A1:  Yes, but there’s a nuance - we’ll get there soon.

Q: I may have missed it but what did the 28 represent in the previous slide?

A1:  It was the "address" (URL) where the string lives in memory.

A2:  Just the address of that String

Q: The code is really small, could he possibly zoom in?

Q: As a result, you can also modify the lists as Mehran taught yesterday?

A1:  For strings it's a little different. You'll see that soon.

Q: could we us for elem in example:

A1:  Yes, we’ll get there

Q: Is there a particular reason he did range(len(example)) rather than range(length) since he created that variable already?

A1:  He could have used length. He just wanted to show what the loop would look like if you didn't use a separate variable.

Q: what is the difference between doing: example=“Hi mom” and example=[‘h’, ’i’, ‘ ’, ‘m’, ‘o’, ‘m’]?

A1:  The first is a string and the next is a list - we’ll talk about the difference between them in a second

Q: can you explain again what “len” is?

A1:  Returns the length of the string

Q: how come you cant command it to print(example[i])?

A1:  You can

Q: how do you type the emoji?

A1:  Depends on your OS! You can just copy and paste if need be.

Q: How do you include emoji's in Python?

A1:  Depends on your OS! You can just copy and paste if need be.

Q: How does a string version of a number get stored? For example is x = ’28’ and list with only one element equal to 28 or with 2 elements, the first 2 and the second 8?

A1:  Here, x is really a string, which is has some similarities to a list (link indexing to get characters), but it's not actually a "list". It's a different type.

Q: In the example, the print function took two statements to print (both i and the letter). How many different statements can you add to the print function to print?

A1:  As many as you want

Q: should that be x.strip() or strip(x) or something, otherwise how does strip “know” it’s referring to x?

A1:  Good point! That should be x.strip()

Q: can we use string functions mentioned here on lists?

A1:  Nope

Q: Does x.find tell you where it is?

A1:  Yeah, it tells you the index of the string you’re searching for

A2:  Yes, it returns the index of the first appearance of the string you're trying to find.

Q: what’s strip again?

A1:  It removes whitespace from the start and end of the string

Q: So digit is like “integer” for Python?

A1:  A digit in this context is ‘0’-‘9’

Q: sorry would you mind clarifying the final 3 again?

A1:  isdigit - whether a string comprises entirely of digits isalpha - whether a string comprises entirely of letters isspace - whether a string comprises entirely of spaces

Q: What did x.alpha do? And the one where the answer was #2?

A1:  x.isalpha() returns whether the string consists entirely of alphabetical characters, and .find returns the index of a string you’re searching for.

Q: Are periods and commas alphas?

A1:  No, they’re not letters.

Q: what ch stands for?

A1:  character, but it’s just a variable

Q: you forgot to print! how did it print?

A1:  it’s printed in main.

Q: Would only_number = [] not work for making a new string?

A1:  No, that makes a list

Q: How can you run a doctest again?

A1:  In the terminal: python3 -m doctest -v foo.py  In Pycharm: right-click and select ‘run doctest’

Q: would only_number += ch work?

A1:  Yes

Q: Just to confirm, when we use replace or other commands, it creates a new string; it doesn’t modify it?

A1:  Yep!

Q: So ord takes a value and gives you the index value for your character?

A1:  Yep

Q: what do the 28 and 91 mean?

A1:  They are addresses in memory where those strings live

Q: how does x.replace work then?

A1:  It returns a modified string

Q: how do you delete strings youre not using anymore?

A1:  del var_name

A2:  But that’s not a particularly common thing to do

Q: but once you change your string can you access the old one if they share the same name?

A1:  Nope!

Q: can we then search through the heap to find the 'original' string before any concatenation happens?

A1:  Not in Python, but that would also be _really_ slow

Q: just to be sure, you can’t access it but it still exists?

A1:  At some point, your OS or Python will clear it up, but yes, it doesn’t get deleted when the reference gets reassigned

A2:  Python will reclaim the memory for that string eventually.

Q: What about string.replace? does it modify the string or make a new one

A1:  Makes a new string.

A2:  Returns a new one

Q: Can you also do negative numbers to go backwards through indexes of a string like you can for lists

A1:  Yep

Q: how are you changing result everytime if strings are immutable? or is each iteration different?

A1:  You are assigning a new strong over result no each iteration of the loop.

Q: Is this a situation where you could also do ‘for ch in str: result = ch + result’?

A1:  yep!

Q: For the third version of reverse string, are you allowed to have a function with nothing in it but a return?

A1:  Yep

Q: why can strings be normalized if they are immutable?

A1:  All string functions return a new function!

Q: If strings are immutable, why can we normalize a string one character at a time?

A1:  We make a new string each time we add a new character!

Q: so it also counts the characters besides from beign a palindrome?

A1:  Yep!

Q: will the review sessions recorded

A1:  yes

Q: Will there be YEAH hours for assignment 4?

Q: when looking at the three reverse string functions, i didn’t understand how the first two were able to reverse the str.

A1:  it built a new string! one character at a time

Q: How does the program find this huge sentence as a palindorme since there are spaces in different places when you reverse it? Does it ingore the spaces?

A1:  normalize removes all the space and punctuation. Check out the worked example (look in the navbar on cs106a.stanford.edu)

Q: but you were looping through the string in the forward direction and then adding them. Wouldn’t that just return the same string?