1/18
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Subset (Set Operation)
Test whether every element in set s is in set t using the syntax: s \le t
Superset (Set Operation)
Test whether every element in set t is in set s using the syntax: s \ge t
Union (Set Operation)
Create a new set with elements from both set s and set t using the syntax: s | t
Intersection (Set Operation)
Create a new set with elements common to both set s and set t using the syntax: s & t
Difference (Set Operation)
Create a new set with elements in set s but not in set t using the syntax: s - t
Symmetric Difference (Set Operation)
Create a new set with elements in either set s or set t but not both, using the syntax: s \text{^} t
f-string format specifier: Left-align string in a field of 20 characters
Syntax: {name:<20}
f-string format specifier: Center-align string in a field of 20 characters
Syntax: {name:^20}
f-string format specifier: Right-align string in a field of 20 characters
Syntax: {name:>20}
f-string format specifier: Right-align string with zero-padding in a field of 20 characters
Syntax: {name:0>20}
f-string example for zero-padding numbers
for i in range(5, 16):
print(f'{i:03}')
# Example output for i = 5: '005'
f-string example for floating-point precision
pi = 3.14159265
f'Pi is equal to {pi:.4f}'
# Output: 'Pi is equal to 3.1416'
Cloning Lists (Slicing)
Creating a new list that is a shallow copy of an existing list by using full slicing.
Example:
a = [5, 3, 6, 1]
b = a[:]
a[1] = 42
# 'a' is now [5, 42, 6, 1], but 'b' remains [5, 3, 6, 1]
List Comprehension
A concise way to create lists.
Syntax: [\text{expression for item in iterable if conditional}]
Example: [x*2 for x in range(5) if x % 2 == 0] (results in [0, 4, 8])
Escape Sequence: \n
Ends the current line of text and starts a new one (newline character).
Escape Sequence: \t
Skips to the next "tab stop" in the text (tab character).
Escape Sequence: \'
Used to include a single quote within a string delimited by single quotes without ending the string.
Escape Sequence: \"
Used to include a double quote within a string delimited by double quotes without ending the string.
Escape Sequence: \
Used to include a literal backslash character in a string.