array, slices, functions

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

1/35

encourage image

There's no tags or description

Looks like no tags are added yet.

36 Terms

1
New cards

Looping Array Elements

You can use the for in loop to loop through all the elements of an array.

Print each item in the cars array:

for x in cars:

print(x)

2
New cards

.append() and .insert()

list_name.append(“thing”)

list_name.insert(index, ““)

3
New cards

del format

del list_name[index]

4
New cards

Reverses the order of the list

reverse()

5
New cards

break

exits the loop immediately, and unconditionally ends the loop's operation; the program begins to execute the nearest instruction after the loop's body;

6
New cards

continue

behaves as if the program has suddenly reached the end of the body; the next turn is started and the condition expression is tested immediately.

7
New cards

bubble sort

if my_list[i] > my_list[i + 1]:

swapped = True

my_list[i], my_list[i + 1] = my_list[i + 1], my_list[i]


8
New cards

my_list[start:end]

slice

9
New cards

start

is the index of the first element included in the slice;

10
New cards

end

is the index of the first element not included in the slice.

11
New cards

in

checks if a given element (its left argument) is currently stored somewhere inside the list (the right argument) ‒ the operator returns True in this case.

12
New cards

not in

checks if a given element (its left argument) is absent in a list ‒ the operator returns True in this case.

13
New cards

sort()

mylist.sort()

14
New cards

len()

len(myfirst)

15
New cards

How to display arrays a single time with range()

for i in range(list):

print(list[i])

16
New cards

parameters exist only inside functions in which they have been defined

True

17
New cards

assigning a value to the parameter is done at the time of the function's invocation,

True

18
New cards

parameters live inside functions (this is their natural environment)

True

19
New cards

arguments exist outside functions,

True

20
New cards

return

functions to return a value

21
New cards

[:]

Full list

22
New cards

[start:]

From start to the end

23
New cards

[:stop]

From beginning to stop

24
New cards

[::step]

Every step-th item from start to end

25
New cards

[start:stop:step]

Full control

26
New cards

[::-1]

reverses the list

27
New cards

[::2]

every second item

28
New cards

None

mustn't take part in any expressions
when you assign it to a variable (or return it as a function's result)
when you compare it with a variable to diagnose its internal state.

29
New cards

adding key pairs to dictionary

dictionary['swan'] = 'cygne'
dictionary.update({"duck": "canard"})

30
New cards

Removing a key

del dictionary['dog']

31
New cards



32
New cards

R


33
New cards



34
New cards



35
New cards
36
New cards