CPSC150- Final Exam Review

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/31

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

32 Terms

1
New cards

Integer (int)

whole numbers 5, 2, -20

2
New cards

float(float)

decimal numbers, 2.0, 3.7

3
New cards

String (str)

text in quotes "Hello World", "CPSC150"

4
New cards

Containers

set, list, dictionary, tuple

5
New cards

Strings

a collection of letters/characters

6
New cards

Immutable

you cannot change a character in a string. Any function returns a new string (.upper(), .lower())

7
New cards

Concatenation

adding strings together

8
New cards

Length

gives how many characters are in a string

9
New cards

String Formatting

use f"{var_name}"

10
New cards

Lists

-an ordered collection of items that can be edited (mutable)

- created using square brackets []

- accessed based on the index of the element

- index starts at 0

11
New cards

.append(item)

adds to end of list

12
New cards

.remove(item)

removes this item

13
New cards

Dictionary

- a collection of key - value pairs

- created using curly braces

- my_dict = { key : value }

14
New cards

Adding to a Dictionary

my_dict[key] = value

15
New cards

Accessing a Dictionary

my_dict[key] -> value

16
New cards

Tuples

- collection of ordered items that are immutable

- created using parentheses ()

- Accessed based on the index of the element

- Use Square Brackets to Access

17
New cards

Sets

- Mutable, Unordered collection of unique elements

- created using curly braces {}

18
New cards

Scope

- Passing a primitive (int, string, character) to a function does not change the original USE RETURN

- Passing a list to a function does not update the original list

19
New cards

User Input

- Use input() function

- Make sure you convert the correct type

20
New cards

Booleans

statements that evaluate to be True or False

21
New cards

If-else statements

-If Statements only execute if the statement is true

- Elif (Else-If) executes if the previous if statement is not true and it is true

- else executes only if everything above it has not

22
New cards

Functions

always start with the def notation and then any params in ()

- the parameter names are what is used in the function, these do not necessarily have to be the variable names outside of the function

- A variable that is defined inside the function is a local variable. If you want to use it outside then need to use return

23
New cards

Print

this only prints the variable/output to the console

24
New cards

Return

this returns the variable to where the function was called so that you can use it

25
New cards

Default parameters

assigned if no parameters are given

26
New cards

For Loop

used when you know how many iterations you want to go through

27
New cards

2 main types of for loops

using range an iterating through the sequence

28
New cards

While Loop

used when you are unsure how long you want the loop to run for

29
New cards

Nested Loops

-for every iteration of the outer loop the inner loop fully runs

-can be good for iterating through 2D lists

30
New cards

break

fully exists out of the loop

31
New cards

continue

exists the current iteration, but continues the loop

32
New cards

Files

- make sure to use with open() so that you don't have to worry about closing the file

- 'r' to read, 'w' to write, 'a' to append