Introduction to Python

Similar documents
Scientific Programming, Analysis, and Visualization with Python. Mteor 227 Fall 2015

Programming Languages

Chapter 13: Program Development and Programming Languages

McGraw-Hill The McGraw-Hill Companies, Inc.,

Programming in Python. Basic information. Teaching. Administration Organisation Contents of the Course. Jarkko Toivonen. Overview of Python

CRASH COURSE PYTHON. Het begint met een idee

Exploring Algorithms with Python

CS 40 Computing for the Web

Introduction to Python

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

Introduction to Python

Unlocking the True Value of Hadoop with Open Data Science

Introduction to Python for Text Analysis

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

CSE 373: Data Structure & Algorithms Lecture 25: Programming Languages. Nicki Dell Spring 2014

Chapter 1. Dr. Chris Irwin Davis Phone: (972) Office: ECSS CS-4337 Organization of Programming Languages

REALbasic versus Visual Basic

Computational Mathematics with Python

Introduction to the course, Eclipse and Python

Session 85 IF, Predictive Analytics for Actuaries: Free Tools for Life and Health Care Analytics--R and Python: A New Paradigm!

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

The Clean programming language. Group 25, Jingui Li, Daren Tuzi

A Python Tour: Just a Brief Introduction CS 303e: Elements of Computers and Programming

Python for Scientific Computing.

What is a programming language?

Computational Mathematics with Python

Computational Mathematics with Python

Announcements FORTRAN ALGOL COBOL. Simula & Smalltalk. Programming Languages

Lecture 1: Introduction

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

CSE 130 Programming Language Principles & Paradigms

Programming Languages

Intro to scientific programming (with Python) Pietro Berkes, Brandeis University

Analytic Modeling in Python

6.170 Tutorial 3 - Ruby Basics

Java in Education. Choosing appropriate tool for creating multimedia is the first step in multimedia design

Chapter 12 Programming Concepts and Languages

CSCI 3136 Principles of Programming Languages

Python Programming: An Introduction to Computer Science

Programming Languages & Tools

Fall 2012 Q530. Programming for Cognitive Science

CS 51 Intro to CS. Art Lee. September 2, 2014

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

HEP data analysis using jhepwork and Java

CSE 307: Principles of Programming Languages

Chapter 2 Writing Simple Programs

Introduction to Python

Exercise 0. Although Python(x,y) comes already with a great variety of scientic Python packages, we might have to install additional dependencies:

Software: Systems and. Application Software. Software and Hardware. Types of Software. Software can represent 75% or more of the total cost of an IS.

Big Data Paradigms in Python

Embedded SQL. Unit 5.1. Dr Gordon Russell, Napier University

PYTHON Basics

Informatica e Sistemi in Tempo Reale

The power of IBM SPSS Statistics and R together

Functional Programming

Python Programming: An Introduction to Computer Science

n Introduction n Art of programming language design n Programming language spectrum n Why study programming languages? n Overview of compilation

Multiprocess System for Virtual Instruments in Python

Chemical and Biological Engineering Calculations using Python 3. Jeffrey J. Heys

Availability of the Program A free version is available of each (see individual programs for links).

Computer Programming In QBasic

Python for Data Analysis and Visualiza4on. Fang (Cherry) Liu, Ph.D PACE Gatech July 2013

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Moving from CS 61A Scheme to CS 61B Java

Chapter 1: Getting Started

Efficiency Considerations of PERL and Python in Distributed Processing

Scientific Programming in Python

SCIENTIFIC COMPUTING AND PROGRAMMING IN THE CLOUD USING OPEN SOURCE PLATFORMS: AN ILLUSTRATION USING WEIGHTED VOTING SYSTEMS

Fundamentals of Programming Languages

Characteristics of Java (Optional) Y. Daniel Liang Supplement for Introduction to Java Programming

2/1/2010. Background Why Python? Getting Our Feet Wet Comparing Python to Java Resources (Including a free textbook!) Hathaway Brown School

Semantic Analysis: Types and Type Checking

Chapter 13: Program Development and Programming Languages

Semester Review. CSC 301, Fall 2015

Scientific Programming with Python. Randy M. Wadkins, Ph.D. Asst. Prof. of Chemistry & Biochem.

Selecting Features by Attributes in ArcGIS Using the Query Builder

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

HTSQL is a comprehensive navigational query language for relational databases.

Data Science Certificate Program

Python 2 and 3 compatibility testing via optional run-time type checking

Postprocessing with Python

Everything you wanted to know about using Hexadecimal and Octal Numbers in Visual Basic 6

Data Analytics at NERSC. Joaquin Correa NERSC Data and Analytics Services

CS101 Lecture 24: Thinking in Python: Input and Output Variables and Arithmetic. Aaron Stevens 28 March Overview/Questions

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Apache Spark 11/10/15. Context. Reminder. Context. What is Spark? A GrowingStack

Chapter 15 Functional Programming Languages

Object systems available in R. Why use classes? Information hiding. Statistics 771. R Object Systems Managing R Projects Creating R Packages

Efficiency of Web Based SAX XML Distributed Processing

Introduction Installation Comparison. Department of Computer Science, Yazd University. SageMath. A.Rahiminasab. October9, / 17

SEO - Access Logs After Excel Fails...

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

1.1 WHAT IS A PROGRAMMING LANGUAGE?

Transcription:

1 Daniel Lucio March 2016

Creator of Python https://en.wikipedia.org/wiki/guido_van_rossum 2

Python Timeline Implementation Started v1.0 v1.6 v2.1 v2.3 v2.5 v3.0 v3.1 v3.2 v3.4 1980 1991 1997 2004 2010 2012 2015 1989 1994 2000 2001 2003 2006 2008 2009 2011 2014 Conceived v1.5 v2.2 v2.4 v2.6 v3.3 v0.9.0 v2.0 v2.7 v3.5 https://en.wikipedia.org/wiki/history_of_python 3

What is Python? Python is a widely used high-level, general-purpose, interpreted, dynamic programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C++ or Java. The language provides constructs intended to enable clear programs on both a small and large scale. https://en.wikipedia.org/wiki/python_%28programming_language%29 4

What is Python? Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive standard library. https://en.wikipedia.org/wiki/python_%28programming_language%29 5

What is Python? Python interpreters are available for installation on many operating systems, allowing Python code execution on a wide variety of systems. Using third-party tools, such as Py2exe or Pyinstaller, Python code can be packaged into stand-alone executable programs for some of the most popular operating systems, allowing the distribution of Python-based software for use on those environments without requiring the installation of a Python interpreter. https://en.wikipedia.org/wiki/python_%28programming_language%29 6

What is Python? Python combines remarkable expressive power with very clean, simple, and compact syntax. Python is easy to learn and very well suited for an introduction to computer programming. Python is also quite similar to Matlab and a good language for doing mathematical computing. It is easy to combine Python with compiled languages, like Fortran, C, and C++, which are widely used languages for scientific computations. A seamless integration of Python with Java is offered by a special version of Python called Jython. https://en.wikipedia.org/wiki/python_%28programming_language%29 7

What is Python? Website: www.python.org Filename extensions.py,.pyc,.pyd,.pyo, pyw,.pyz OS: Cross-platform Major implementations: CPython, IronPython, Jython, PyPy Influenced by: ABC, ALGOL 68, C, C++, Dylan, Haskell, Icon, Java, Lisp, Modula-3, Perl Supported Paradigms: object-oriented, imperative, functional, procedural, reflective https://en.wikipedia.org/wiki/python_%28programming_language%29 8

Choosing a language There are many different programming languages in the world, and most were designed to perform tasks in a certain way or even make it easier for a particular profession s work to be done with greater ease. Choosing the correct tool makes your life easier! Python vs R vs SAS vs SQL 9

About Python Python (general purpose): Many data scientists prefer to use Python because it provides a wealth of libraries, such as NumPy, SciPy, MatPlotLib, pandas, and Scikit-learn, to make data science tasks significantly easier. Python is also a precise language that makes it easy to use multi-processing on large datasets, reducing the time required to analyze them. The data science community has also stepped up with specialized IDEs, such as Anaconda, that implement the IPython Notebook concept, which makes working with data science calculations significantly easier 10

About R R (special purpose statistical): In many respects, Python and R share the same sorts of functionality but implement it in different ways. Depending on which source you view, Python and R have about the same number of proponents, and some people use Python and R interchangeably (or sometimes in tandem). Unlike Python, R provides its own environment, so you don t need a third-party product such as Anaconda. However, R doesn t appear to mix with other languages with the ease that Python provides. 11

About R R (special purpose statistical): In many respects, Python and R share the same sorts of functionality but implement it in different ways. Depending on which source you view, Python and R have about the same number of proponents, and some people use Python and R interchangeably (or sometimes in tandem). Unlike Python, R provides its own environment, so you don t need a third-party product such as Anaconda. However, R doesn t appear to mix with other languages with the ease that Python provides. 12

About SAS SAS (business statistical analysis): The Statistical Analysis System (SAS) language is popular because it makes data analysis, business intelligence, data management, and predictive analytics easy. The SAS Institute originally created SAS as a means to perform statistical analysis. In other words, this is a business-specific language one used to make decisions rather than to perform handwriting analysis or to detect specific natural patterns. 13

About SAS SAS (business statistical analysis): The Statistical Analysis System (SAS) language is popular because it makes data analysis, business intelligence, data management, and predictive analytics easy. The SAS Institute originally created SAS as a means to perform statistical analysis. In other words, this is a business-specific language one used to make decisions rather than to perform handwriting analysis or to detect specific natural patterns. 14

About SQL SQL (database management): The most important thing to remember about Structured Query Language (SQL) is that it focuses on data rather than tasks. Businesses can t operate without good data management the data is the business. Large organizations use some sort of relational database, which is normally accessible with SQL, to store their data. Most Database Management System (DBMS) products rely on SQL as their main language, and DBMS usually has a large number of data analysis and other data science features built in. Because you re accessing the data natively, there is often a significant speed gain in performing data science tasks this way. Database Administrators (DBAs) generally use SQL to manage or manipulate the data rather than necessarily perform detailed analysis of it. 15

Version 2 or 3? A common problem among Python programmers is to choose between v2 or v3. The general recommendation is to go for version 3, but programs are then not compatible with v2 and vice versa. There is still a problem that much useful mathematical software in Python has not yet been ported to v3! Therefore, scientific computing with Python still goes mostly with v2. A widely used strategy for software developers who want to write Python code that works with both versions, is to develop for v2.7, which is very close to what is accepted in v3, and then use the translation tool 2to3 to automatically translate the code to v3. 16

Version 2 or 3? When using v2.7, one should employ the newest syntax and modules that make the differences between version 2 and 3 very small! The two most significant differences for most users between v2 and v3 are: a/b implies float division in v3 if a and b are integers print Hello in v2 must be turned into the function call print( Hello ) in v3. You can read more at: https://wiki.python.org/moin/python2orpython3 17

Version 2 or 3? Where to learn more about the differences between one or the other: https://wiki.python.org/moin/python2orpython3 18

Version 2 or 3? http://astrofrog.github.io/blog/2015/05/09/2015-survey-results/ 19

Version 2 or 3? http://astrofrog.github.io/blog/2015/05/09/2015-survey-results/ 20

Version 2 or 3? http://astrofrog.github.io/blog/2015/05/09/2015-survey-results/ 21

Keywords The following identifiers are used as reserved words, or keywords of the language, and cannot be used as ordinary identifiers. They must be spelled exactly as written here: v2.7 v3.5.1 and del from not while as elif global or with assert else if pass yield break except import print class exec in raise continue finally is return def for lambda try False class finally is return None continue for lambda try True def from nonlocal while and del global not with as elif if or yield assert else import pass break except in raise 22

How to get Python? https://www.python.org/downloads/ 23

Scientific Distributions It s entirely possible to obtain a generic copy of Python and add all of the required data science libraries to it. The process can be difficult because you need to ensure that you have all the required libraries in the correct versions to ensure success. In addition, you need to perform the configuration required to ensure that the libraries are accessible when you need them. Fortunately, going through the required work is not necessary because a number of Python data science products are available for you to use. These products provide everything needed to get started with science projects. 24

First example For example, if you want to display something on-screen, you simply tell Python to print it, like this: v2.7 print "Hello There!" v3.5.1 print("hello There!") 25

Scientific Distributions It s entirely possible to obtain a generic copy of Python and add all of the required data science libraries to it. The process can be difficult because you need to ensure that you have all the required libraries in the correct versions to ensure success. In addition, you need to perform the configuration required to ensure that the libraries are accessible when you need them. Fortunately, going through the required work is not necessary because a number of Python data science products are available for you to use. These products provide everything needed to get started with science projects. 26

Continuum Analytics Anaconda https://www.continuum.io/downloads 27

Enthought Canopy Express https://www.enthought.com/canopy-express/ Enthought Canopy Express is a free product for producing both technical and scientific applications using Python. Only Canopy Express is free, the full Canopy product comes at a cost. One of the advantages of Canopy Express is that Enthought is heavily involved in providing support for both students and teachers. People also can take classes, including online classes, that teach the use of Canopy Express in various ways (see https://training.enthought.com/ courses). Also offered is live classroom training specifically designed for the data scientist; read about this training at https:// www.enthought.com/ services/training/data-science. 28

Python(x,y) http://python-xy.github.io/ The python(x,y) Integrated Development Environment (IDE) is a community project hosted on Google at https://code.google.com/p/ pythonxy/. It s a Windows-only product, so you can t easily use it for cross-platform needs. (In fact, it supports only Windows Vista, Windows 7, and Windows 8.) Because pythonxy uses the GNU General Public License (GPL) v3 (see http://www.gnu.org/licenses/gpl.html), you have no add-ons, training, or other paid features to worry about. No one will come calling at your door hoping to sell you something. In addition, you have access to all the source code for pythonxy, so you can make modifications if desired. 29

WinPython https://winpython.github.io/ The name tells you that WinPython is a Windows-only product that you can find at http://winpython.sourceforge.net/. This product is actually a takeoff of pythonxy and isn t meant to replace it. Quite the contrary: WinPython is simply a more flexible way to work with pythonxy. You can read about the motivation for creating WinPython at http://sourceforge. net/p/winpython/wiki/roadmap/. The bottom line for this product is that you gain flexibility at the cost of friendliness and a little platform integration. However, for developers who need to maintain multiple versions of an IDE, WinPython may make a significant difference. 30

HW for next class Type the following piece of code and run it. NOTE: This program will need a parameter from the command line! #!/usr/bin/env python import sys, math r = float(sys.argv[1]) s = math.sin(r) print "Hello, World! sin(" + str(r) + ")=" + str(s) 31

References Python Crash Course: A Hands-On, Project-Based Introduction to Programming Eric Matthes A Primer on Scientific Programming with Python Hans Petter Langtangen Python for Data Science For Dummies John Paul Mueller, Luca Massaron 32

Questions? 33

Indentation Python relies on indentation to create various language features, such as conditional statements. One of the most common errors that developers encounter is not providing the proper indentation for code. if 1 < 2: print("1 is less than 2") 34

Operators The following tokens are operators v2.7 + - * ** / // % << >> & ^ ~ < > <= >= ==!= <> v3.5.1 + - * ** / // % @ << >> & ^ ~ < > <= >= ==!= 35