1/38
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
What does it mean that strings are immutable in Python?
Once a string is created, its contents cannot be changed in place.
How do you change a string in Python?
You need to reassign it to a new string, which moves it to a different memory address.
How does parameter passing work in Python?
Parameter passing is done by object reference; functions receive a reference to the original object.
What does it mean that lists are mutable?
You can change the contents of a list in place.
How can you modify a list in a function?
You can design functions that modify lists in place without needing to return a new list.
What is the purpose of the .join() method in Python?
It joins the elements of a sequence into a string using a specified separator.
How do you use the open() function in Python?
The open() function is used to open a file for reading, with the file name passed as the first argument.
How does the for loop work when reading a file in Python?
The file object is used as an iterator to read the file one line at a time.
What does the strip() method do in Python?
It removes leading and trailing whitespace from a string.
What is the difference between void functions and fruitful functions?
Void functions do not return a value, while fruitful functions return a value.
What is recursion in programming?
A recursive function is one that calls itself and needs a base case to stop recursion.
What is the call stack and how does it work?
The call stack manages function calls in a last-in, first-out manner, creating stack frames for each function call.
What happens to a stack frame when a function completes?
When a function completes, its stack frame is popped off the stack.
What is refactoring in programming?
Refactoring is the process of improving the design of existing code without changing its external behavior.
What is the importance of the id() function in Python?
It is used to view the memory address of an object.
What do the append() and remove() methods do for lists?
append() adds an element to the end of a list, while remove() removes the first occurrence of a value from a list.
What does the split() method do in Python?
It splits a string into a list of words based on whitespace.
What are some strategies for preparing for the midterm exam?
Review class material, practice problems, and participate actively in discussions.
Strings
are sequences of characters used to represent text in Python.
Lists
Same as strings but can be changed
for c in St:
will be character
for i in range(len(st)):
St[i]=h
will change the character at index i in the string st to h.
s = ‘MontyPython’
s[6:12]
M o n t y P y t h o n
0 1 2 3 4 5 6 7 8 9 10
range from 6-12 so ython
txt = “Hello, welcome to my world.”
result = txt.find(“e”, 7)
print (result)
find the first e after position 7 which is 8 in the string txt.
What position does the index start at
it always starts at 0
s = “Hello, Python!”
s2 = s[0:5]
print(s2)
H e l l o
0 1 2 3 4
5th is excluded
isdigit()
st.isalpha()
True
‘is’ returns true/false
capitalize()
st = ‘abc’
st.capitalize()
‘Abc’
upper()
st.upper()
‘ABC"‘
fruitful function
returns a function as an integer value
void function
does not return function

what is the bug?
for char in s
if char in vowels:
result.append(char)
char = 'b'
char = 'o' r=['o','o]
please find code and fix it
["Hello", "Goodbye", "Ciao!"]
loop 1: i = 0, Words[i] = "Hello"
'Ciao!' =/ '!'
if "!" not in words [i]! is not included in string (at end) if …”Ciao!”, “!” it would work

sections out the word
txt = f"The price is {price} dollars"
print(txt)What does this do
This is a formative string, curly brackets will place in the saved ‘price’
name = "sam"
id = 944986464
print("My name is + name + id")will this work
No it needs f string or
t = (1,2)
l = [1,2]What will be the output for these 2 functions?
without coma it is a tuple even without ()