Giter Site home page Giter Site logo

damichalek / python-intro Goto Github PK

View Code? Open in Web Editor NEW

This project forked from epurpur/python-intro

0.0 0.0 0.0 463 KB

uva library workshop on introduction to python

Home Page: https://github.com/alonzi/python-intro

License: GNU General Public License v3.0

Python 100.00%

python-intro's Introduction

-Last updated 23-January-2023

Who am I?

  • Erich Purpur

  • Research Librarian for Science & Engineering

  • I'm a librarian here at UVA Research Data Services

    -I'm a liaison to various engineering departments. Basically, if they need stuff from the library I try to make it available for them. I do quite a bit of teaching both in one off workshops like this, ongoing series (PhD+), and for-credit courses. I teach courses releated to python programming and Geographic Information Systems (GIS) I also sometimes help people with GIS (Geographic Information Systems) projects and programming-related questions. And do various side projects as they arise.

  • Feel free to interrupt with questions!

Welcome to the UVA Library

Other Upcoming Workshops

Workshop Date Time
Intro to Version Control w/ Git + Github Wednesday 1/25 10:00 - 11:30
Intro to Python Wednesday 2/1 12:00 - 1:30
Intro to Regular Expressions Wednesday 2/8 10:00 - 11:30
Data Analysis in Python with Matplotlib and Pandas Wednesday 2/8 10:00 - 11:30
Python Natural Language Processing / Sentiment Analysis Wednesday 2/15 12:00 - 1:30
Geospatial Data + Mapping in Python Wednesday 2/22 10:00 - 11:30
Python and APIs Wednesday 3/1 12:00 - 1:30
Python Web Scraping Wednesday 3/15 12:00 - 1:30

Getting Anaconda + Python (this will take some time)

Getting the files we are working with today

  • 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)

Goals for Today

  1. Get python running
  2. Learn some fundamentals
  3. Learn how to help yourself (Most Important!)

Outline

  1. Strings
  2. Print Statement
  3. Numbers (Int and Float)
  4. Errors
  5. Functions (Built-ins and custom)
  6. Lists, Loops, Booleans, Indexing
  7. Dictionaries
  8. Import
  9. Conditional Statements
  10. Mutable vs. Immutable data types

What is Python?

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/)

Difference between R and Python? (Simplified)

  • 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

A brief history

Let's Get to It (hopefully everyone is done installing)

  • 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

Strings

  • 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

Comments

We also introduce comments here, the computer will ignore everything after the '#' symbol. There are other forms but we'll see them later on.

Variables

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

Error Messages

  • Tell you when (and hopefully where) your code breaks.
  • Some are more readable and helpful than others
  • Read them from the bottom up

Functions

  • 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)

Indexing

  • 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

Lists

  • represented like functions but with [...]
  • there is an order to the items
  • the items can be of any type

Dictionary

  • 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

loops - used when you want to repeat code

  • 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)
  • 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

if statements

  • 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

Import

This is an important topic

Mutablility

  • 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

Scripting vs Programming

It's a matter of modularity. Programs are designed to be modular and work with other programs. Scripts are designed to be single use.

How to Help Yourself and Learn More

Learning Resources

Self Help via the Internet

  • Google * Ex: "How to make dictionary python" * Ex: "python decorators"

  • Stack Overflow (https://stackoverflow.com/) * 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 (https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g) - If you have a question about a python programming concept, Corey Schafer has covered it

  • Practice Python (http://www.practicepython.org/) * Coding challenges for programmers of all levels

  • Python Tutor (http://pythontutor.com/) * Visualize what your code is doing step-by-step * Has limitations once you start importing libraries

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.