Home
Explore
Exams
Login
Get started
Home
Engineering
Computer Science
LV - Python
5.0
(2)
Rate it
Studied by 8 people
5.0
(2)
Rate it
View linked note
Call with Kai
Learn
Practice Test
Spaced Repetition
Match
Flashcards
Knowt Play
Card Sorting
1/19
Earn XP
Description and Tags
Computer Science
Add tags
Study Analytics
All Modes
Learn
Practice Test
Matching
Spaced Repetition
Call with Kai
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
No study sessions yet.
20 Terms
View all (20)
Star these 20
1
New cards
indexing
making and printing the list:
listFood = \[“chocolate”, “cheese”, “fruit”\]
print(listFood\[1\])
2
New cards
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
3
New cards
append()
to add an item to the end of a list:
listNames.append(“sally”)
4
New cards
insert()
to insert an item into a specific place on the list:
listNames.insert(2, “elisa”)
5
New cards
remove()
to remove an item from a list:
listNames.remove(“penelope”)
6
New cards
pop()
takes out an item at a certain index in a list:
listNames.pop(3)
7
New cards
del list\[\]
deletes permanently the item at a particular index:
del listNames\[4\]
8
New cards
sort()
sorts a list into ascending order:
listNames.sort()
9
New cards
len()
prints out the number of terms in a list:
print(len(listNames))
10
New cards
index()
returns the number where the item appears in the list:
print(listNames.index(“freya”))
11
New cards
using “in”
“in” is used to say if something is in the list then something else should happen:
if “elsa” in listNames:
12
New cards
validation - range
user is asked to input something between a certain range:
numRange = int(input(“Please enter a number between 11 and 18”))
13
New cards
validation - lookup
user is asked to input something from a store of data:
country = input(“Please enter a country from the list above”)
14
New cards
“==”
to compare terms:
if item == “a”:
15
New cards
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)
16
New cards
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)
17
New cards
def functionName():
the way of naming a function:
def addTwoNumbers():
print(2+2)
18
New cards
Formal parameters
items in brackets which are variables:
def addTwoGivenNumbers(num1 + num2):
print(num1+num2)
19
New cards
Actual parameters
items in brackets which are actual things:
addTwoNumbers(6+7):
print(6+7)
20
New cards
return functions
instead of printing, it is returning something:
def returnAdditionOfTwoNumbers(num1+num2):
return num1+num2