
Quick Python Review for Class ATM 240 Fall 2022
Dive into a quick review of Python basics covering lists, tuples, dictionaries, functions, if/else blocks, loops, slicing, and practical class exercises. Get ready for your ATM 240 class with this concise overview.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Class #3 ATM 240 ~ Fall 2022 Robert Fovell rfovell@albany.edu 1
Quick (partial) review - 1 Lists are defined between [square brackets]. Lists can mix and match different types: numbers, strings, etc.. One unique data type is None Lists are mutable. a = [ I , have ,3, red ] a.append( violins ) a.insert(3, nice ) a[5] = cars print(a) 2
Quick (partial) review - 2 Tuples are created between (round brackets). Tuples are immutable. Dictionaries are delineated between {curly braces}. The form of each dictionary element is key :value Functions can be defined to perform frequent operations and simplify code Functions must be defined before use Functions are invoked by calling their name and passing their arguments def area(radius, pi=None): area = pi*(radius**2) return area area(3,3.15159) 3
Quick (partial) review - 3 If/elif/else blocks if a == 3: do this elif a == 2: do that else: do this other thing # For loops can act over a list, including a sequence of numbers In this example, range provides a sequence of integers 0-5 for i in range(6): do this thing 4
Quick (partial) review - 4 Slicing ais a list print(a[1:3]) prints the 2nd and 3rditems from the left ( oneth and twoth ) cis a string print(c[1:3]) prints the 2nd and 3rd characters from the left a[-1] and c[-1] access the last item or character True, False, and None 5
Class lab Spawn a Terminal (see next slide), and type these after the prompt: cd /spare11/atm240/yournetid cp ../lin_chapter03_exercise.ipynb . cp ../lin_chapter04.ipynb . [hit return] [hit return] [hit return] Then, type exit at the prompt and hit return When that s done, you can close the tab In your Files view, click on the atm240 link, then click on lin_chapter03_exercise.ipynb to launch the notebook 6
For this class We will finish lin_chapter03.ipynb We will execute lin_chapter03_exercise.ipynb We will (at least start on) lin_chapter04.ipynb 8
For next class Finish reading Lin-2012 Chapter 4 9