2. Intro To Python Flashcards
What is the library “BeautifulSoup” used for?
BeautifulSoup is the Python standard for scraping data from websites
How do you write comments?
Add a # at the start of the line
What is the convention for naming python variables?
all lowercase letters, with words separated by underscores,
eg. “assists_per_game”
How would you insert variables inside a string?
Do that using an f-string (add the letter f just preceding the quotation mark), with variables between curly brackets
eg.
f’{description} by {starting_fwd}!’
What string method allows you to capitalize all letters?
.upper()
How would you replace something in a string?
Use the .replace() method.
eg.
‘Cristiano Ronaldo, Man U’.replace(‘Man U’, ‘Real Madrid’)
This will output a string that literally replaces “Man U” by “Real Madrid”
What method allows you to remove whitespace from a string?
.lstrip()
’ lionel messi’.lstrip()
–> becomes:
‘lionel messi’
What is the difference between = and ==?
= is an assignment operator
== is equals (checks a variable for a result)
What are “strings, integers, floats and bools” called?
Primitives
–> They are the basic building block types
What are “lists and dicts” called?
Containers
(Sometimes also called “collections”)
–> Because they hold other values
How can you recognise a list?
Uses square brackets,
eg.
roster_list = [‘ruben dias’, ‘gabriel jesus’, ‘riyad mahrez’]
How do you return one element from a list?
print(roster_list[0])
–> Prints the first item in the list
What is a section of a list called?
A slice
How do you return a section of a list? (a slice?)
A slice returns from the first up to the last number,
roster_list[0:2]
–> Prints the first two items in the list
What do dicts have?
Keys and values,
roster_dict = {‘CB’: ‘ruben dias’, ‘CF’: ‘gabriel jesus’, ‘RW’: ‘riyad mahrez’}
In this case ‘CB’ is a key and ‘ruben dias is a value’