# Intro to Python
## Week 2 Thurs
## `def`ining functions
### [Prof. Lane](#links) #### [dlane@sdccd.edu](mailto:dlane@sdccd.edu)
#### Virtual Office Hours 10AM & 7PM: #### [sdccd-edu.zoom.us/my/dlane](https://sdccd-edu.zoom.us/my/dlane) #### ``[slides.nlpia.org](https://slides.nlpia.org/)`` --- ## Attendance
#### In Sublime Text: - Hit `[Ctrl]+[P]` to find your `*buggy*.py` file - Hit `[Ctrl]+[Shift]+[F]`, type a Python keyword, then hit `[Enter]` - Find code you have written before so you can answer the attendance question
- When I call your name, raise your hand - Name a `type` or function and explain it note: - Tell us about your programming journey - Find new `str.*` methods? - Understand `print` `input` `type` and `=` better? - Learn anything about where files are on your computer? - [officefile:///home/hobs/code/mesa_python/mesa_python/data/private-fall26/runestone_roster_fall26.ods](officefile:///home/hobs/code/mesa_python/mesa_python/data/private-fall26/runestone_roster_fall26.ods) --- ## New Skills - ``str.upper``, ``.lower``, ``.split`` - ``def``ining functions - `for` loops - drawing with `turtle.Turtle` - ``str.format`` note: - You'll learn 2 new keywords `def`, `for` - and a new use for `in` --- ## Announcements ### [syllabus](https://sdccd.instructure.com/courses/2505751/assignments/syllabus) - Attendance drops Sunday and Monday - Labor Day on Monday! - Give me feedback! ### Zoom Office Hours Monday 10AM & 7PM ### [sdccd-edu.zoom.us/my/dlane](https://sdccd-edu.zoom.us/my/dlane) note: - good news and bad news - I start dropping absentee students on Sunday - Labor Day on Monday! - I will be at zoom office hours on Monday - Show up at office hours if you have not attended most of our class sessions - Making attendance is not enough, you need to participate for the entire class --- ## Assignments due Sunday - [Runestone.Academy Module 2](https://runestone.academy/assignment/student/chooseAssignment) - [Canvas Module 2](https://sdccd.instructure.com/courses/2505751/modules) note: - next week [GitLab.com/mesa_python/fall26](https://gitlab.com/mesa_python/fall26) --- ## ``def``ine `print_and_return()` ```python def print2(text): return print(text) ``` note: - improve python style - what does `print()` return - what does our version of `print` return - add a docstring --- ## Hints - improve python style - what does `print()` return? - what does our version of `print` return - add a docstring --- ```python def print_and_return(text): print(text) return text ``` --- ## Hints - add a ``__doc__``string (a special ``# comment``) first! - make it useful in a text adventure or conversation - add another argument --- ```python def greet(greeting, name): """ Greet the user by name enthusiastically! >>> greet('Hi', 'bob') 'Hi Bob!' """ text = greeting + ' ' + name + '!' print(text) return text ``` [starter code](./wk2/wk2.py) --- ```python for i in range(3): print(i) ``` [starter code](./wk2/wk2.py) note: - Which words are keywords? - Notice any new punctuation or whitespace? - Which words are built-in function names? - Which words are variable names? - Which words are literal values? --- Have a play with the new keywords and functions for this week: - `def` - `return` - `for` - `range` note: - Which of these are Python keywords? - Which are built-in Python functions? --- Advanced looping (__iteration__) keywords: - `continue` - `break` --- ### Links 1. [slides.nlpia.org](https://slides.nlpia.org) 2. [starter code](./wk2/wk2.py)