Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro To Pete Alonzi University of Virginia Library

Similar presentations


Presentation on theme: "Intro To Pete Alonzi University of Virginia Library"— Presentation transcript:

1 Intro To Pete Alonzi University of Virginia Library
Research Data Services February 14, 2017

2 Outline Installation Getting our sea legs – terminals, and text editors, and IDEs Math and variables Functions Python Data Types Loops Logic Import Odds and ends

3 Installation of Python
Two Notes Language (python) vs language distribution (anaconda) Python 2 vs Python 3

4 Programming vs Python For this workshop we are not requiring any previous knowledge of python or of computer programming. As a result we will be explaining fundamental concepts of each. Our emphasis is on the python but we will spend time on programming as well.

5 Brief history of Python - https://www.python.org/
Designed by Guido van Rossum 1991 successor to the ABC language Python 2.0 was released on October 2000 Python 3.0  was released on December 2008

6 Let’s Open Spyder

7 Programs – “Hello World!”
In programming the classic first program is called “Hello World!”

8 Math and Variables Python knows math!
1+2 Python uses variables to reference things (for example some math). X = 1+2 The “=“ is special. It doesn’t mean equals to. It means refers to. Variable

9 Math and Variables Math operations Variable rules + - * / ** % //
* / ** % // Variable rules Must start with a letter Have a type

10 Functions Functions are prewritten pieces of code that perform one specific task. Let’s take a look at type(…) Function code name arguments

11 Programs – “Hello World!”
In programming the classic first program is called “Hello World!”

12

13 Data Types - Strings A string is a string of characters
“apple” “blue42” “iamtheverymodelofamodernmajorgeneral” “7hills” Helper functions: string.lower(), string.upper() And many more, check out the online docs

14 Indexing fruit = ‘ a p p l e ‘

15 Data Types – Strings - Slicing
Reference elements of a string with […:…] [from:up to but not including]

16 Data Types - Lists Lists are represented: name[…]
Contains a list of elements of various types You can even have a list of lists Lots of helper functions Reference with [...] and can slice too! Don’t forget tuples: name(…) and immutable

17 Data Types - Dictionary
Dicts are represented: name{…} Elements are a pair: key:value The keys are strings and values are anything Lots of helper functions

18 Loops – FOR For loop syntax: for ___ in ___ :
The first blank is a new variable The second blank is an iterable eg: for x in range(10): print x

19 Loops – WHILE While loop syntax: while <boolean>:
The boolean is checked every iteration eg: while i<10: print i; i+=1

20 If statements Normally your code progresses linearly
Use an if statement for a fork in the road Syntax: if <boolean>: ______ else: _______ To chain multiples together use elif

21 Import modules A great feature of python is modularity. Lots of people have developed lots of good modules. A great module is called numpy Eg: numpy.random.randn() But my favorite module is called pandas Use nltk for text manipulation

22 Import modules A great feature of python is modularity. Lots of people have developed lots of good modules. A great module is called numpy Eg: numpy.random.randn() But my favorite module is called pandas

23 Comments Every programming language has a way for you to include text to help explain the code. In python you can make a comment two ways. # everything after a # is commented Everything between ’’’ is a comment ‘’’

24 File input/output (I/O)
Reading from a file

25 File input/output (I/O)
Writing to a file


Download ppt "Intro To Pete Alonzi University of Virginia Library"

Similar presentations


Ads by Google