Giter Site home page Giter Site logo

chaitalih / python-intro Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alonzi/python-intro

0.0 0.0 0.0 371 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

python-intro

uva library workshop on introduction to python

Who am I?

Welcome to the UVA Library

Getting Python (this will take some time)

  • Windows

  • Mac

  • terminology time

    • programming langugage vs software distribution
    • python2 vs python3

Goals for Today

  1. Get python running
  2. Get comfortable with python
  3. Learn how to look up help

Outline

  1. Strings and Functions
  2. Data types
  3. Loops
  4. Logic
  5. How to import (aka the most important part)

A quick note

Today we are working on python. However there is some knowledge of programming that is required. Don't worry if you don't know it, please ask questions. I will do my best to answer them. And I will also do my best to indicate when something is a python specific detail and when it is a programming in general item.

A brief history

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

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

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 the most important topic
  • The import command let's you bring in code from another file and use it
  • one example: random number generation
    • import numpy
    • numpy.random.randn()
  • There are two steps info on conda info on pip
    1. install the module, eg: shell]$ conda install numpy
    2. python>>> import numpy

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.

Ways to Practice

  1. Write some code
  2. Ask a friend to review it
  • Beginning
    • Flip a coin (~10 lines)
    • Play rock, paper, scissors (~25 lines)
  • Intermediate
    • Guess a secret number between 1 and 10. With hints. (~20 lines)
    • Dice rolling program
  • Expert
    • Play blackjack
    • Play roulette

python-intro's People

Contributors

alonzi avatar buckleydowdle avatar hyung-test avatar ohashin2g avatar laurenneal avatar

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.