1/38
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
+
Strings can be added together with this operator
ord()
Converts character to ASCII value
char()
Converts ASCII value to character
len()
Returns the length of a word as an integer
word[ ]
Used to find the character at a particular index
word[-1]
Will begin reading from the final character of the string
word.isalpha()
Returns a boolean value of whether ALL characters are alphabetical
word.isupper()
Returns a boolean value of whether ALL characters are uppercase
word[ ].isupper
Checks if a single character at a particular index is uppercase (boolean)
word.upper()
Converts a word to all upper case characters
word.swapcase()
Switches the case of all characters in a string
list_name = [ ]
Creates a new list
list[ ]
Format for list indexing
list.append(“item”)
Adds a string “item” to a list
list.remove(“item”)
Removes a string “item” from a list
list.index(“item”)
Find the index of string “item” in a list
min(list)
Find the minimum value in a list
max(list)
Find the maximum value in a list
list.split(“,”)
Turns a list into a string separated by a comma
try:
Place risky code — that may throw an error — under this block header
except:
Write code under this block header that will run if there is an exception (runtime error etc.) in a previous block
def name():
Creates a function called name
Local variable
A variable in a function that is only used in that function (e.g. a variable ‘x’ can be use din multiple functions because of this)
def name(a, b, c,):
Define a function called “name“ with functions a, b, and c
dict = { }
Create an empty dictionary named “dict’
:
Keys and values are separated by this
,
Key-value pairs are separated buy this
dict[key]
In a dictionary named ‘dict’ find the value of ‘key’
dict[new_key] = new_value
In a dictionary called ‘dict’ add a key called ‘new_key’ and a value called ‘new_value’
dict.keys()
Find all keys in a dictionary called ‘dict’
dict.values()
Find all values in a dictionary called ‘dict’
dict.items()
Find all key-value pairs in a dictionary called ‘dict’
for key in dict.keys()
Iterate over all keys in a dictionary called ‘dict’
for key, value in dict.items()
Iterate over all key-value pairs in a dictionary called ‘dict’
class class_name
Create a class called ‘class_name)
def __init_(self):
Write the constructive method used in classes (use one less underscore in the second “dunder” because of Knowt formatting)
def __init_(self, name, age):
Create a constructor method that passes arguments ‘name’ and ‘age’
dog1 = dogs(“Albert”)
Create a new instance of a class called ‘dogs’ and assign it to a variable ‘dog1’. The new dogs name is ‘Albert’.
dog1.name
Using the class ‘dogs’, find the name of ‘dog1’ (dog1 is already assigned as a variable)