Tutorial 7
Tutorial 7
Tutorial 7
3. Debugging Tips
4. Quizizz!
Midterm Review Guidelines If you don't
know, now
you know,
folks!
• Please put everything except
your smartphone/laptop in your bags
• No writing utensils on the desk
• During review, the exam paper
must always be visible to the front of
the classroom
• Attempts at dishonesty will be handled
according to the PhF Honor Code
Midterm Handout, based on last names
• A – E: Luc
• G – P: Maritina
• Q – S: Lucas
• T – Z: Isabelle
GROUP BEHAVIOUR
No Groups One Group Multiple Groups Non Capturing Groups
findall() returns a list findall() returns a list of findall() returns a list of Use (?:...) for parts of the
of the entire matches. matches from that group. tuples, each containing the pattern you don't want to
matches of the groups. capture. They don’t affect
findall()'s output.
re.findall(r'(\d+)', '123 abc')
re.findall(r'\d+', '123 abc') gives ['123']. re.findall(r'(\d+)(\w+)', '123abc') re.findall(r'(?:\d+)(\w+)', '123abc')
gives ['123']. gives [('123', 'abc')] gives ['abc']
Raw Strings: Use raw strings (r'') for patterns to avoid issues with Python’s escape sequences.
Functions and Control Flow
• Mixing Up Variables: Getting confused between • Go Step by Step: In your IDE use the
different types of variables (like those used only debugger to go through your code line by
inside a function and those used throughout your line. It helps you see exactly what's
program). happening at each step.
• Check for Mistakes: Make sure your
function is getting the right inputs and
check each part of your function to see
AND READ YOUR ERRORS ! where it might be going wrong.
Errors, a crash course A lot of the time, your errors will tell you exactly what's wrong and where!
Python's pretty cool like that! Here's more: https://docs.python.org/3/tutorial/errors.html
Pepe- Kermit-
type frog type frog
Objects - Kermit and Pepe Themselves
Docstrings
Documentation Strings
• special strings that describe what a function, class,
module, or package does.
F-strings • important part of writing clean, maintainable code.
Formatted strings literals ⇢ """This is a docstring. It explains the purpose of the
• offer a concise and convenient way to embed function."""
expressions inside string literals, using curly braces {}
• efficient and readable
⇢ name = "Kermit"; greeting = f"Hello, {name}!
Method Description
capitalize() Converts the first character to uppercase
Converts string to lower case for caseless
casefold()
matching
count(pattern, string) Counts occurrences of a substring
find(pattern, string) Finds the first occurrence of the substring
Joins the elements of an iterable into a
join(iterable)
string
Replaces occurrences of a substring with
replace(pattern, new pattern)
new
QUICK SURVEY
IT'S QUIZZIZZ TIME!
Questions?