Midterm 2

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/38

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 6:24 PM on 11/19/24
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

39 Terms

1
New cards

What does it mean that strings are immutable in Python?

Once a string is created, its contents cannot be changed in place.

2
New cards

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.

3
New cards

How does parameter passing work in Python?

Parameter passing is done by object reference; functions receive a reference to the original object.

4
New cards

What does it mean that lists are mutable?

You can change the contents of a list in place.

5
New cards

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.

6
New cards

What is the purpose of the .join() method in Python?

It joins the elements of a sequence into a string using a specified separator.

7
New cards

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.

8
New cards

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.

9
New cards

What does the strip() method do in Python?

It removes leading and trailing whitespace from a string.

10
New cards

What is the difference between void functions and fruitful functions?

Void functions do not return a value, while fruitful functions return a value.

11
New cards

What is recursion in programming?

A recursive function is one that calls itself and needs a base case to stop recursion.

12
New cards

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.

13
New cards

What happens to a stack frame when a function completes?

When a function completes, its stack frame is popped off the stack.

14
New cards

What is refactoring in programming?

Refactoring is the process of improving the design of existing code without changing its external behavior.

15
New cards

What is the importance of the id() function in Python?

It is used to view the memory address of an object.

16
New cards

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.

17
New cards

What does the split() method do in Python?

It splits a string into a list of words based on whitespace.

18
New cards

What are some strategies for preparing for the midterm exam?

Review class material, practice problems, and participate actively in discussions.

19
New cards

Strings

are sequences of characters used to represent text in Python.

20
New cards

Lists

Same as strings but can be changed

21
New cards

for c in St:

will be character

22
New cards

for i in range(len(st)):

St[i]=h

will change the character at index i in the string st to h.

23
New cards

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

24
New cards

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.

25
New cards

What position does the index start at

it always starts at 0

26
New cards

s = “Hello, Python!”

s2 = s[0:5]

print(s2)


H e l l o

0 1 2 3 4

5th is excluded

27
New cards

isdigit()

st.isalpha()

True

‘is’ returns true/false

28
New cards

capitalize()

st = ‘abc’

st.capitalize()

‘Abc’

29
New cards

upper()

st.upper()

‘ABC"‘

30
New cards

fruitful function

returns a function as an integer value

31
New cards

void function

does not return function

32
New cards
<p>what is the bug?</p>

what is the bug?

for char in s 
    if char in vowels:
	result.append(char)
	char = 'b'
	char = 'o' r=['o','o]


33
New cards
<p>please find code and fix it </p>

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

34
New cards
term image

sections out the word

35
New cards


36
New cards
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’

37
New cards
name = "sam" 
id = 944986464
print("My name is + name + id")

will this work

No it needs f string or

38
New cards
t = (1,2) 

l = [1,2]

What will be the output for these 2 functions?

without coma it is a tuple even without ()


39
New cards