application Flashcards
1
Q
Review how to create patterns using regular expressions
A
- p…n = any single character
- (ab|cd) = ab or cd
- t(en|wo) = ten or two
- [abc] = a, b, or c
- pyth[aeiou]n = python where the fourth character is a vowel
- [^abc] = any character except a, b, or c
- pyth[^aeiu]n = python where the fourth character is not a vowel except i
- [a-z] any lowercase letter
- [A-Z]ytho[a-z] = python where the first character is uppercase, followed by ytho and a lowercase letter
- [^a-z] = any characters except lowercase letters
- pytho[^b-d] = python where the fifth character is not b, c, or d
- \A = beginning of the string
- \b = beginning or end of a word
- re.search(r”th\B”, “Python”) = th not at the end of the word
- \d = a digit (same as [0-9])
- \D = a non-digit
- \w = any alphanumeric character (a-z, A-Z, 0-9, _)
- \W = any non-alphanumeric character
- \s = a whitespace character
- \S = a non-whitespace character
- \Z = end of the string
- = zero or more occurrences of pattern
- = one or more occurrences of pattern
- ? = zero or one occurrence of pattern
- ^ = starts with a specified pattern
- $ = ends with a specified pattern
- {n} = exactly n occurrences of pattern
- {n,} = at least n occurrences of pattern
- {n,m} = between n and m occurrences (inclusive)
2
Q
Review how to store information in a list, sort the information, and output the information
A
- create a list called information_list containing numerical data [4, 2, 7, 1, 5].
- Use the sort() method to sort the elements of the list in ascending order. If you want to sort in descending order, you can use the reverse=True parameter: information_list.sort(reverse=True).
- To add information to an empty list, .append(listname)
- Finally, we use the print() fnction to output the sorted information.
3
Q
Review how to draw shapes using PyGame
A
- Line - pygame.draw.line(surface, color, (x1, y1), (x2, y2), width)
- Rectangle - pygame.draw.rect(surface, color, (x, y, width, height), outline)
- Rounded rectangle - pygame.draw.rect(surface, color, (x, y, width, height), outline, radius) (radius is 4 numbers, one for each corner. ex, 0,0,0,0)
- Polygon - pygame.draw.polygon(surface, color, points, width)
- Circle - pygame.draw.circle(screen, color, (x, y), radius, width) draws circle with fixed radius
- Ellipse - pygame.draw.ellipse(screen, color, (x, y, width, height), width)