-Last updated 01/21/2025
-
Erich Purpur
-
Research Librarian for Science & Engineering
-
-I'm a Science & Engineering Librarian and a liaison to various Science & Engineering departments here at UVA. Basically, it means that if there is a way for the library to support those departments, I am responsible for making that happen. I also do various other things like teach workshops on technical topics, like the one you are taking today. I also am involved in internal library projects and committees.
- ep9k@virginia.edu
- Brown Science & Engineering Library office i054
-
Feel free to interrupt with questions!
Workshop | Date | Time |
---|---|---|
Intro to Python pt 1 | Tuesday 9/2 | 11:00 - 12:30am |
Intro to Python pt 2 | Tuesday 9/9 | 11:00 - 12:30am |
Python Data Analysis & Visualization | Tuesday 9/16 | 11:00 - 12:30am |
AI Prompt Engineering for Python | Thursday 9/18 | 1:00 - 2:30pm |
Workshop | Date | Time |
---|---|---|
Using Large Language Models Locally | Thursday 9/4 | 1:00 - 2:30pm |
AI Prompt Engineering w/ CLEAR Framework | Thursday 9/11 | 1:00 - 2:30pm |
AI Prompt Engineering for Python | Thursday 9/18 | 1:00 - 2:30pm |
- Go here: https://github.com/epurpur/python-intro
- Click "Clone or Download" (green button in upper right corner)
- Click "Download Zip"
- Unzip that directory and move it somewhere that is easy to find (like your Desktop, for example)
- Get python running
- Learn some fundamentals
- Learn how to help yourself (including ChatGPT / AI)
- Strings
- Print Statement
- Numbers (Int and Float)
- Errors
- Functions (Built-ins and custom)
- Lists, Loops, Booleans, Indexing
- Dictionaries
- Import
- Conditional Statements
- Mutable vs. Immutable data types
From www.python.org: "Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance."
Python is a general purpose programming language used for a huge variety of purposes. It's user community is growing rapidly! (https://stackoverflow.blog/2017/09/06/incredible-growth-python/)
- They are both open source programming languages
- Python is general purpose while R is focused on statistics and data analysis
- However, R has grown hugely and has become much more wide ranging
- You can also do stats with Python. Many packages available
- NumPy
- SciPy
- Pandas
- Designed by Guido van Rossum
- version 1.0 1994
- version 2.0 2000
- version 3.0 2008 (we are currently in python version 3.11)
- logo
- anaconda logo
- We are using Anaconda/Spyder today as it seems to be widely used throughout UVA. Adapted for data scientists
- Spyder is a Programming IDE (Integrated Development Environment)
- text editor
- variable explorer
- console
- control icons
- A string is a 'string' of characters
- 'apple' # letters
- 'blue42' # letters and numbers
- 'i am the very model of a modern major general' # spaces are fine
- '7 hills' # it can even start with a number
We also introduce comments here, the computer will ignore everything after the '#' symbol. There are other forms but we'll see them later on.
You can "save" things as variables. For those curious as to what's going on under the hood...in python a variable is actually just a pointer to the location in memory where the object lives.
-
a = 'apple'
- a is the variable
- = is the assignment operator
- 'apple' (a string) is the object assigned to a
-
Important Note: the assignment operator is not like an equals sign
- a=5
- a=7
- totally works, a was just reassigned to point to 7
- Tell you when (and hopefully where) your code breaks.
- Some are more readable and helpful than others
- Read them from the bottom up
- print(a) # this function will show us what a points to
- we know that print is a function because there is no space between print and the "("
- format of a function: name(arguments)
- we say we "call" a function
- this is super important in python the way to spot a function is no space before a "(" and a letter or number
- python built-in functions
- print(...)
- type(...)
- pow(...)
- in an equation you may see 5*(2+3), you won't seet 5(2+3) (try it and see what happens)
- for objects with an order you can access individual elements
- indexing
- you can also pull out slices
- syntax [X:Y]
- starting at X
- upto but not including Y
- syntax [X:Y]
- represented like functions but with [...]
- there is an order to the items
- the items can be of any type
- represented like lits but with {...}
- there is no order to items
- items contain two pieces: a key and a value represented key:value and the key must be a string
-
for loop
- for X in Y: << code >>
- X is a new variable created on the spot
- Y is some preexisting iterable
- << code >> is a block of code you want to repeat
- eg: for x in range(10): print(x)
- for X in Y: << code >>
-
while loop
- while Z: << code >>
- Z is a boolean
- << code >> is a block of code you want to repeat
- eg: while i<10: print i; i+=1
- while Z: << code >>
- example
- if X: << code A >>
- else: << code B >>
- X is a boolean
- << code A >> is some code
- << code B >> is some code, could be the same
This is an important topic
- The import command let's you bring in code from another file and use it
- one example: random number generation
- import random
- random.randint(0,10)
- import random
- Sometimes packages needed to be installed (3rd party packages)
- pip - (https://pip.pypa.io/en/stable/installing/)
- conda - (https://conda.io/docs/)
- Some data types can be changed, others can't
- Many reasons for this, a big one is performance
- Mutable data types (such as lists) are costly to CPU processingn power
- Immutable data types (like arrays) take less memory and processing power
It's a matter of modularity. Programs are designed to be modular and work with other programs. Scripts are designed to be single use.
-
Pick up a book, there are many available through the UVA library website
- Learn Python 3 the Hard Way (Available for free through UVA libraries)
- Link here
-
Phd+ Course Materials
- All resources available online for free!
- https://learning.rc.virginia.edu/courses/python_introduction/
-
Other resources available at UVA
- Research Data Services - StatLab Fellows
- https://data.library.virginia.edu/statlab/
- statlab@virginia.edu
- Research Computing - Provides high performance computing expertise
-
ChatGPT
- ChapGPT has quickly made huge changes to the programming landscape. It is a hugely powerful tool If you use it the right way!. I think it is a somewhat slippery slope of how to advise new programmers to use ChatGPT (or other AI tools) so I will refer to some best practices. My personal opinion is that you should use AI minimally when you are starting. When you have a better grasp of basic fundamentals, then you can include AI and greatly increase your speed. Never accept ChatGPT code verbatim! Always double check it before including it in your workflows.
- How to Effectively Learn to Program w/ ChatGPT
- Corey Schafer's "How to use ChatGPT"
-
Google
- Ex: "How to make dictionary python"
- Ex: "python decorators"
-
- A question/answer site for programming questions (actually, not just programming any more)
- Not only python
- DO NOT just ask questions, do your research first!
- Odds are very high someone has already asked your question, especially as a novice
-
Youtube
- Corey Schafer
- If you have a question about a python programming concept, Corey Schafer has covered it
- (How to Use ChatGPT by Corey Schafer)[https://www.youtube.com/watch?v=jRAAaDll34Q]
- Corey Schafer
-
- Coding challenges for programmers of all levels
-
- Visualize what your code is doing step-by-step
- Has limitations once you start importing libraries