python

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

1/29

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 1:54 AM on 8/29/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

30 Terms

1
New cards

set( )

{ }

a collection that stores unique values (no duplicates) and is unordered

use .add( ) and .remove( )


2
New cards

range(3)

0, 1, 2

3
New cards

4%3

1 remainder

4
New cards

15 // 4

there are 3 4s in 15

5
New cards

HashSet

a data structure that stores unique elements in no particular order. No duplicate item, cannot access elements by an index, allow null

6
New cards

// for Sudoku

  • // = "which group?" (top/middle/bottom)

    row = (nsquare//n)*x+i # how many

n*n box,

x num box per row,

nsquare is 第几个box

7
New cards

% for sudoku

% = "which position inside the group?" (left/middle/right)

col = (nsquare% n)* x +j # remainder

n*n box,

x num box per row,

nsquare is 第几个box

8
New cards

s[::-1]


s[::-1] means:

start : end : step
-1 = go backwards

9
New cards

\

line continuation character. It means this statement continues on the next line.

10
New cards

world[name] what type does this output

Returns one column as a Series.

11
New cards

world[['name']] what type does this output

dataframe

12
New cards

~

not

13
New cards

filter those name starting with A

df[df['name'].str.startswith('A')]


14
New cards

filter name containing John

df[df['name'].str.contains('John')]


15
New cards
df.sort_values('column_name')


Ascending (default) 少到多

16
New cards
rename


df.rename(columns={'old_name': 'new_name'})


17
New cards

unique

drop_duplicates()


18
New cards

df['name'].str[0:3]

substring

19
New cards

string spaces

.str.strip()

20
New cards

df['name'].str.split(' ')

split by space

21
New cards

df['name'].str.len() how to use this

df[df['name'].str.len() > 5]

22
New cards

replace certain string

.str.replace(old, new)

23
New cards

lambda

means a small function you write in one line.

lambda arguments: expression

def bonus(x):

return x['salary']

becomes lambda x: x['salary']

24
New cards

what does axis 1 mean in apply


axis=1 mean apply function to each row

25
New cards

how to use assign ? what does it do ?

df.assign(new_column=value)

create or modify columns in a DataFrame.

26
New cards

how to use apply ?

df.apply(function, axis=1)

def get_bonus(x): return x['salary'] * 2 df['bonus'] = df.apply(get_bonus, axis=1)

df['bonus'] = df.apply(lambda x: x['salary'] * 2, axis=1)


27
New cards

.assign() syntax


df.assign(new_column=value)

df.assign( bonus=df['salary'] * 0.1 )

28
New cards

what does assign do

.assign() lets you create or modify columns and returns a new DataFrame.

df.assign(new_column=value)


29
New cards

change data

astype(int)


30
New cards


fill in the missing value as 0 in the quantity column

.fillna(0, inplace=True)