LV - Python

studied byStudied by 5 people
5.0(2)
Get a hint
Hint

indexing

1 / 19

flashcard set

Earn XP

Description and Tags

20 Terms

1

indexing

making and printing the list:

listFood = [“chocolate”, “cheese”, “fruit”]

print(listFood[1])

New cards
2

slicing (start, stop, step)

start stop step refers to the positions

[start:stop:step]

start = the index number the index begins

stop = the index number the index ends

step = the jump range

New cards
3

append()

to add an item to the end of a list:

listNames.append(“sally”)

New cards
4

insert()

to insert an item into a specific place on the list:

listNames.insert(2, “elisa”)

New cards
5

remove()

to remove an item from a list:

listNames.remove(“penelope”)

New cards
6

pop()

takes out an item at a certain index in a list:

listNames.pop(3)

New cards
7

del list[]

deletes permanently the item at a particular index:

del listNames[4]

New cards
8

sort()

sorts a list into ascending order:

listNames.sort()

New cards
9

len()

prints out the number of terms in a list:

print(len(listNames))

New cards
10

index()

returns the number where the item appears in the list:

print(listNames.index(“freya”))

New cards
11

using “in”

“in” is used to say if something is in the list then something else should happen:

if “elsa” in listNames:

New cards
12

validation - range

user is asked to input something between a certain range:

numRange = int(input(“Please enter a number between 11 and 18”))

New cards
13

validation - lookup

user is asked to input something from a store of data:

country = input(“Please enter a country from the list above”)

New cards
14

“==”

to compare terms:

if item == “a”:

New cards
15

nested for loops

a loop inside a loop:

x = [1, 2]

y = [4, 5]

for i in x:

for j in y:

print(i, j)

New cards
16

when do you use a nested loop?

if you have multiple lists that you want to do something with, or if you have a list within a list (a nested list)

New cards
17

def functionName():

the way of naming a function:

def addTwoNumbers():

print(2+2)

New cards
18

Formal parameters

items in brackets which are variables:

def addTwoGivenNumbers(num1 + num2):

print(num1+num2)

New cards
19

Actual parameters

items in brackets which are actual things:

addTwoNumbers(6+7):

print(6+7)

New cards
20

return functions

instead of printing, it is returning something:

def returnAdditionOfTwoNumbers(num1+num2):

return num1+num2

New cards

Explore top notes

note Note
studied byStudied by 70 people
... ago
5.0(1)
note Note
studied byStudied by 112 people
... ago
5.0(1)
note Note
studied byStudied by 2 people
... ago
5.0(1)
note Note
studied byStudied by 5 people
... ago
5.0(1)
note Note
studied byStudied by 21 people
... ago
5.0(2)
note Note
studied byStudied by 44 people
... ago
5.0(2)
note Note
studied byStudied by 19 people
... ago
5.0(1)
note Note
studied byStudied by 2606 people
... ago
4.8(12)

Explore top flashcards

flashcards Flashcard (189)
studied byStudied by 9 people
... ago
5.0(1)
flashcards Flashcard (92)
studied byStudied by 3 people
... ago
5.0(1)
flashcards Flashcard (45)
studied byStudied by 15 people
... ago
4.0(1)
flashcards Flashcard (33)
studied byStudied by 11 people
... ago
4.0(1)
flashcards Flashcard (33)
studied byStudied by 2 people
... ago
4.0(1)
flashcards Flashcard (74)
studied byStudied by 9 people
... ago
5.0(1)
flashcards Flashcard (26)
studied byStudied by 16 people
... ago
5.0(1)
LV - Python
flashcards Flashcard (20)
studied byStudied by 5 people
... ago
5.0(2)
robot