PYTHON FOR MEDICAL PHYSICISTS. Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital

Size: px
Start display at page:

Download "PYTHON FOR MEDICAL PHYSICISTS. Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital"

Transcription

1 PYTHON FOR MEDICAL PHYSICISTS Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital

2 TUTORIAL 1: INTRODUCTION Thursday 1 st October, 2015

3 AGENDA 1. Reference list 2. Introduction to Python 3. Getting started with Python 4. Programming basics 5. Python syntax 6. Data structures 7. Flow control 8. Comments

4 REFERENCES Online resources: The Python Tutorial ( Codecademy ( Textbooks (available on N: drive): Python for Scientists: A Curated Collection of Chapters from the O Reilly Data and Programming Library, by O Reilly ( A Primer on Scientific Programming with Python, by Langtangen

5 ABOUT PYTHON Python is an interpreted language the Python interpreter executes statements entered by the user or parsed from a script Python is a popular choice for scientists, with many packages developed for numerical analysis and scientific computation

6 INSTALLING PYTHON Recommend installing the free Anaconda distribution, including science, math, and analysis packages available from continuum.io available for Windows, Mac and Linux operating systems There are currently 2 active branches Python 2.X legacy Python 3.X recommended!

7 INSTALLING ANACONDA

8 PACKAGES Packages extend functionality Anaconda comes with 195 packages that you may find useful, including: Spyder, a development environment numpy, for processing numerical data scipy, containing scientific functions matplotlib, for data visualisation There are useful packages not included in Anaconda, including: pydicom, for reading, modifying and writing DICOM data (pydicom.org) These can be installed using conda or pip

9 RUNNING PYTHON The Python interpreter can be run from the command line or terminal On a Windows PC, you can run Anaconda Command Prompt to start a session with the appropriate environmental paths Running python this way starts the interpreter in interactive mode, such that commands are prompted for via the terminal

10 PYTHON SCRIPTS Instructions can be passed to the Python interpreter interactively, via the terminal In this way the Python interpreter can be used like a calculator, or like Matlab Instructions for the Python interpreter can also be provided in a script Tools exist for just-in-time compilation (done at run time) to help performance (PyPy, Cython)

11 RUNNING PYTHON Integrated development environments (IDEs) often provide an interactive terminal, in addition to an editor suited to writing scripts Common features include: navigation tools syntax highlighting Spyder comes packaged with Anaconda It uses the ipython environment, which comes with tab completion Alternatives: PyCharm IDE featuring code analysis, refactoring and testing tools (developed by JetBrains) Python Tools for Visual Studio supporting Python in VS2015

12 SPYDER Execute current code Editor IPython console

13 BASICS OF PROGRAMMING Programming styles can be referred to as paradigms We ll be discussing structured programming, which features the following flows of control: sequential execution of statements conditional execution of statements (if, else, elif) iterative execution of statements (for, while) In a later tutorial, we will discuss object-oriented programming

14 PSEUDO CODE Pseudocode is description of an algorithm or computer programs that is designed for human reading Pseudocode is especially useful if you aren t familiar with the syntax of a programming language, as you can translate it later Facilitates top-down design: breaking problem down into smaller problems, that can be individually solved Example of pseudocode: for every pixel in a gamma evaluation image, add 1 to number of total points if pixel value > 1, add 1 to number of failed points if number of failed points / number of total points < 0.9 print Plan Failed otherwise print Plan Passed

15 PYTHON SYNTAX The syntax of a programming language is the set of rules that defines how the code should be structured Examples of syntactical rules include quotation marks should be used when typing a string parentheses should be paired keywords should not be used as identifiers A couple of notes on Python: Python uses whitespace to structure code, unlike the C family, Java, etc. which use curly braces: {,} Variables in Python are dynamically typed (Python: num = 3; C: int num = 3)

16 DATA TYPES Type Description Syntax int integer 1 float floating point number 1.0 complex complex number j str character string string bytes immutable sequence of bytes bytes([1,10,100]) bytearray mutable sequence of bytes bytearray([1,10,100]) list mutable list of objects [1.0, 2.0, 3.0] tuple immutable list of objects (1.0, 2.0, 3.0) set mutable list of unique objects {1.0, 2.0, 3.0} frozen set immutable list of unique objects frozenset([1.0, 2.0, 3.0]) dict dictionary of key and value pairs {1: first, 2: second }

17 OPERATORS Sign Operator = assignment + addition - subtraction & negation * multiplication / division // floor division % modulo (i.e. remainder) ** exponentiation Augmented assignment is possible: num = 2 num += 3 num == 5 returns true Division is typed 5 / 2 = / 2.0 = // 2.0 = 2

18 BOOLEAN OPERATORS Sign Operator == equality!= inequality <, <= less than (or equal to) >, >= greater than (or equal to) and or is not ^ logical and logical or identity boolean negation logical xor for booleans (bitwise operator for ints) Equality is not identity: [1,2,3] == [1,2,3] returns true [1,2,3] is [1,2,3] returns false

19 METHODS Methods are functions attached to objects Methods encapsulate a block of statements that are executed when the method is called Methods can accept arguments (objects passed to the method) Methods can return an object In Python, the syntax for calling a method is: result = method(argument1, argument2) In Python, the syntax for calling a method is: def method(argument):... return result

20 WHY METHODS? Abstracting (encapsulating) code that is repeated in your application into distinct methods comes with multiple benefits: reduced redundancy increased readability improved refactoring (it becomes simpler for the author to make changes to the code) decreased interdependence between software modules supports recursion

21 DATA STRUCTURES Lists represent a sequence of objects Lists can contain mixed types, e.g. ([1, 2.3, a ]) Lists are mutable and Tuples are immutable (meaning that the contents cannot be changed without a new tuple being created) Method append(x) extend(l) insert(i,x) remove(x) pop() clear() index(x) sort() reverse() copy() Description add x to list add list L to list add x at position I remove (first) x remove, return last item remove all items get index of (first) x sort the list reverse the list copy the list

22 DATA STRUCTURES A set is similar to a list, but does not allow duplicate elements Sets are unordered A frozenset is an immutable version of set A dictionary, also known as an associative array, is a list indexed by keys (as opposed to indices). For example: dct = { Ichi : 1, Ni : 2} dct[ Ichi ] == 1 # returns true Ichi in dct # returns true

23 FLOW CONTROL The if statement is used to conditionally execute a block of code It can be combined with else and elif (else if) Example: if chi_reduced > 1: print model does not capture the data elif chi_reduced == 1: print model fits the data else: print model over-fits the data

24 FLOW CONTROL The for statement is used to iterate over a sequence: names = [ alice, bob ] for name in names: print(arr[index]) It can be combined with the range() function to allow iteration over a sequence of numbers: The while statement is used to iterate conditionally Example: def fib(n): a, b = 0, 1 while a < n: print(a, end= ) a, b = b, a+b print() for index in range(5): print(arr[index])

25 DOCUMENTATION Documentation is an important part of developing software and one component is the annotation of code with in-line comments Single line comments can be added using a hash character (#) Mutli-line comments can be added using three quotation marks as a delimiter (""") Example: #this is a comment num = 3 # assign 3 to num """ This is a multi-line comment that spans 2 lines """

26 DOCUMENTATION A docstring is a specifically formatted comment that is retained by the interpreter when encountered These comments can be accessed using the help (or the doc attribute for an object) These are created within Python as the first statement following a definition of function, method, module or class For example: def my_method(self): """The method's docstring"""

27 EXAMPLE: SEVEN29.MCC FILES # import functionality import sys from StringIO import StringIO import numpy as np # take list of files as an argument for the script files = sys.argv[1:] # iterate over files for file in files: f = open(file,'r') o = StringIO() # for every line in the file that contains a # for lines in f: if '#' in lines: o.write(lines) # close the.mcc file f.close() o.seek(0) # load lines in numpy array seven = np.loadtxt(o) # fill a 27x27 matrix with detector readings out = np.zeros((27,27)) for i in range(0,27): out[:,i] = seven[i*27:i*27+27,1] # write to file fname = file[:-3]+'txt np.savetxt(fname, out, fmt='%.4f', delimiter='\t') o.close() # continued

28 NEXT TUTORIAL: USING PACKAGES, JUPYTER NOTEBOOKS, AND CODING EXAMPLES

ARTIFICIAL INTELLIGENCE AND PYTHON

ARTIFICIAL INTELLIGENCE AND PYTHON ARTIFICIAL INTELLIGENCE AND PYTHON DAY 1 STANLEY LIANG, LASSONDE SCHOOL OF ENGINEERING, YORK UNIVERSITY WHAT IS PYTHON An interpreted high-level programming language for general-purpose programming. Python

More information

Webgurukul Programming Language Course

Webgurukul Programming Language Course Webgurukul Programming Language Course Take One step towards IT profession with us Python Syllabus Python Training Overview > What are the Python Course Pre-requisites > Objectives of the Course > Who

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Introduction to Python Part 1. Brian Gregor Research Computing Services Information Services & Technology

Introduction to Python Part 1. Brian Gregor Research Computing Services Information Services & Technology Introduction to Python Part 1 Brian Gregor Research Computing Services Information Services & Technology RCS Team and Expertise Our Team Scientific Programmers Systems Administrators Graphics/Visualization

More information

Python Training. Complete Practical & Real-time Trainings. A Unit of SequelGate Innovative Technologies Pvt. Ltd.

Python Training. Complete Practical & Real-time Trainings. A Unit of SequelGate Innovative Technologies Pvt. Ltd. Python Training Complete Practical & Real-time Trainings A Unit of. ISO Certified Training Institute Microsoft Certified Partner Training Highlights : Complete Practical and Real-time Scenarios Session

More information

Beyond Blocks: Python Session #1

Beyond Blocks: Python Session #1 Beyond Blocks: Session #1 CS10 Spring 2013 Thursday, April 30, 2013 Michael Ball Beyond Blocks : : Session #1 by Michael Ball adapted from Glenn Sugden is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike

More information

Introduction to Python Part 2

Introduction to Python Part 2 Introduction to Python Part 2 v0.2 Brian Gregor Research Computing Services Information Services & Technology Tutorial Outline Part 2 Functions Tuples and dictionaries Modules numpy and matplotlib modules

More information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

1. BASICS OF PYTHON. JHU Physics & Astronomy Python Workshop Lecturer: Mubdi Rahman

1. BASICS OF PYTHON. JHU Physics & Astronomy Python Workshop Lecturer: Mubdi Rahman 1. BASICS OF PYTHON JHU Physics & Astronomy Python Workshop 2017 Lecturer: Mubdi Rahman HOW IS THIS WORKSHOP GOING TO WORK? We will be going over all the basics you need to get started and get productive

More information

Introduction to Python: Data types. HORT Lecture 8 Instructor: Kranthi Varala

Introduction to Python: Data types. HORT Lecture 8 Instructor: Kranthi Varala Introduction to Python: Data types HORT 59000 Lecture 8 Instructor: Kranthi Varala Why Python? Readability and ease-of-maintenance Python focuses on well-structured easy to read code Easier to understand

More information

PYTHON NUMPY TUTORIAL CIS 581

PYTHON NUMPY TUTORIAL CIS 581 PYTHON NUMPY TUTORIAL CIS 581 VARIABLES AND SPYDER WORKSPACE Spyder is a Python IDE that s a part of the Anaconda distribution. Spyder has a Python console useful to run commands quickly and variables

More information

ENGR 102 Engineering Lab I - Computation

ENGR 102 Engineering Lab I - Computation ENGR 102 Engineering Lab I - Computation Learning Objectives by Week 1 ENGR 102 Engineering Lab I Computation 2 Credits 2. Introduction to the design and development of computer applications for engineers;

More information

Course Introduction and Python Basics

Course Introduction and Python Basics Course Introduction and Python Basics Johan Falkenjack 2018-01-15 Course Introduction Python > Data Science 3 hp pass/fail 3 lectures, 3 labs (2 sessions for each lab) Python Basics Programming Paradigms

More information

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15 1 LECTURE 1: INTRO Introduction to Scientific Python, CME 193 Jan. 9, 2014 web.stanford.edu/~ermartin/teaching/cme193-winter15 Eileen Martin Some slides are from Sven Schmit s Fall 14 slides 2 Course Details

More information

Introduction to Python

Introduction to Python Introduction to Python Jon Kerr Nilsen, Dmytro Karpenko Research Infrastructure Services Group, Department for Research Computing, USIT, UiO Why Python Clean and easy-to-understand syntax alldata = cpickle.load(open(filename1,

More information

Advanced Algorithms and Computational Models (module A)

Advanced Algorithms and Computational Models (module A) Advanced Algorithms and Computational Models (module A) Giacomo Fiumara giacomo.fiumara@unime.it 2014-2015 1 / 34 Python's built-in classes A class is immutable if each object of that class has a xed value

More information

Introduction to Python

Introduction to Python May 25, 2010 Basic Operators Logicals Types Tuples, Lists, & Dictionaries and or Building Functions Labs From a non-lab computer visit: http://www.csuglab.cornell.edu/userinfo Running your own python setup,

More information

And Parallelism. Parallelism in Prolog. OR Parallelism

And Parallelism. Parallelism in Prolog. OR Parallelism Parallelism in Prolog And Parallelism One reason that Prolog is of interest to computer scientists is that its search mechanism lends itself to parallel evaluation. In fact, it supports two different kinds

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

APT Session 2: Python

APT Session 2: Python APT Session 2: Python Laurence Tratt Software Development Team 2017-10-20 1 / 17 http://soft-dev.org/ What to expect from this session: Python 1 What is Python? 2 Basic Python functionality. 2 / 17 http://soft-dev.org/

More information

Session 1: Introduction to Python from the Matlab perspective. October 9th, 2017 Sandra Diaz

Session 1: Introduction to Python from the Matlab perspective. October 9th, 2017 Sandra Diaz Session 1: Introduction to Python from the Matlab perspective October 9th, 2017 Sandra Diaz Working with examples in this course Git repository Work: Exercises we will be interactively working on Slides

More information

Table of Contents EVALUATION COPY

Table of Contents EVALUATION COPY Table of Contents Introduction... 1-2 A Brief History of Python... 1-3 Python Versions... 1-4 Installing Python... 1-5 Environment Variables... 1-6 Executing Python from the Command Line... 1-7 IDLE...

More information

Introduction to Machine Learning. Useful tools: Python, NumPy, scikit-learn

Introduction to Machine Learning. Useful tools: Python, NumPy, scikit-learn Introduction to Machine Learning Useful tools: Python, NumPy, scikit-learn Antonio Sutera and Jean-Michel Begon September 29, 2016 2 / 37 How to install Python? Download and use the Anaconda python distribution

More information

https://lambda.mines.edu Why study Python in Principles of Programming Languages? Multi-paradigm Object-oriented Functional Procedural Dynamically typed Relatively simple with little feature multiplicity

More information

Babu Madhav Institute of Information Technology, UTU 2015

Babu Madhav Institute of Information Technology, UTU 2015 Five years Integrated M.Sc.(IT)(Semester 5) Question Bank 060010502:Programming in Python Unit-1:Introduction To Python Q-1 Answer the following Questions in short. 1. Which operator is used for slicing?

More information

CS Advanced Unix Tools & Scripting

CS Advanced Unix Tools & Scripting & Scripting Spring 2011 Hussam Abu-Libdeh slides by David Slater March 4, 2011 Hussam Abu-Libdeh slides by David Slater & Scripting Python An open source programming language conceived in the late 1980s.

More information

Ch.1 Introduction. Why Machine Learning (ML)? manual designing of rules requires knowing how humans do it.

Ch.1 Introduction. Why Machine Learning (ML)? manual designing of rules requires knowing how humans do it. Ch.1 Introduction Syllabus, prerequisites Notation: Means pencil-and-paper QUIZ Means coding QUIZ Code respository for our text: https://github.com/amueller/introduction_to_ml_with_python Why Machine Learning

More information

Large-Scale Networks

Large-Scale Networks Large-Scale Networks 3b Python for large-scale networks Dr Vincent Gramoli Senior lecturer School of Information Technologies The University of Sydney Page 1 Introduction Why Python? What to do with Python?

More information

Basic Python Revision Notes With help from Nitish Mittal

Basic Python Revision Notes With help from Nitish Mittal Basic Python Revision Notes With help from Nitish Mittal HELP from Documentation dir(module) help() Important Characters and Sets of Characters tab \t new line \n backslash \\ string " " or ' ' docstring

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

Scientific Python. 1 of 10 23/11/ :00

Scientific Python.   1 of 10 23/11/ :00 Scientific Python Neelofer Banglawala Kevin Stratford nbanglaw@epcc.ed.ac.uk kevin@epcc.ed.ac.uk Original course authors: Andy Turner Arno Proeme 1 of 10 23/11/2015 00:00 www.archer.ac.uk support@archer.ac.uk

More information

Webinar Series. Introduction To Python For Data Analysis March 19, With Interactive Brokers

Webinar Series. Introduction To Python For Data Analysis March 19, With Interactive Brokers Learning Bytes By Byte Academy Webinar Series Introduction To Python For Data Analysis March 19, 2019 With Interactive Brokers Introduction to Byte Academy Industry focused coding school headquartered

More information

GE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING

GE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING GE8151 - PROBLEM SOVING AND PYTHON PROGRAMMING Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING 1) Define Computer 2) Define algorithm 3) What are the two phases in algorithmic problem solving? 4) Why

More information

CME 193: Introduction to Scientific Python Lecture 1: Introduction

CME 193: Introduction to Scientific Python Lecture 1: Introduction CME 193: Introduction to Scientific Python Lecture 1: Introduction Nolan Skochdopole stanford.edu/class/cme193 1: Introduction 1-1 Contents Administration Introduction Basics Variables Control statements

More information

Scientific Computing: Lecture 1

Scientific Computing: Lecture 1 Scientific Computing: Lecture 1 Introduction to course, syllabus, software Getting started Enthought Canopy, TextWrangler editor, python environment, ipython, unix shell Data structures in Python Integers,

More information

Here n is a variable name. The value of that variable is 176.

Here n is a variable name. The value of that variable is 176. UNIT II DATA, EXPRESSIONS, STATEMENTS 9 Python interpreter and interactive mode; values and types: int, float, boolean, string, and list; variables, expressions, statements, tuple assignment, precedence

More information

Numerical Methods. Centre for Mathematical Sciences Lund University. Spring 2015

Numerical Methods. Centre for Mathematical Sciences Lund University. Spring 2015 Numerical Methods Claus Führer Alexandros Sopasakis Centre for Mathematical Sciences Lund University Spring 2015 Preface These notes serve as a skeleton for the course. They document together with the

More information

Python. Department of Computer Science And Engineering. European University Cyprus

Python. Department of Computer Science And Engineering. European University Cyprus 1 Python VICKY PAPADOPOULOU LESTA, Assistant Professor, Member at AHPC group MICHALIS KYPRIANOU, member of the AHPC group(internship project) Department of Computer Science And Engineering European University

More information

DSC 201: Data Analysis & Visualization

DSC 201: Data Analysis & Visualization DSC 201: Data Analysis & Visualization Python and Notebooks Dr. David Koop Computer-based visualization systems provide visual representations of datasets designed to help people carry out tasks more effectively.

More information

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: Numeric Types There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: 1-123 +456 2. Long integers, of unlimited

More information

Introduction to Python. Dmytro Karpenko Research Infrastructure Services Group, Department for Research Computing, USIT, UiO

Introduction to Python. Dmytro Karpenko Research Infrastructure Services Group, Department for Research Computing, USIT, UiO Introduction to Python Dmytro Karpenko Research Infrastructure Services Group, Department for Research Computing, USIT, UiO Research Computing Services tutorial and courses November 3-7, 2014 Why python

More information

Introduction to Python (All the Basic Stuff)

Introduction to Python (All the Basic Stuff) Introduction to Python (All the Basic Stuff) 1 Learning Objectives Python program development Command line, IDEs, file editing Language fundamentals Types & variables Expressions I/O Control flow Functions

More information

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2 Python for Analytics Python Fundamentals RSI Chapters 1 and 2 Learning Objectives Theory: You should be able to explain... General programming terms like source code, interpreter, compiler, object code,

More information

STA141C: Big Data & High Performance Statistical Computing

STA141C: Big Data & High Performance Statistical Computing STA141C: Big Data & High Performance Statistical Computing Lecture 1: Python programming (1) Cho-Jui Hsieh UC Davis April 4, 2017 Python Python is a scripting language: Non-scripting language (C++. java):

More information

Lecture 0. Introduction to Python. Randall Romero Aguilar, PhD II Semestre 2018 Last updated: July 12, 2018

Lecture 0. Introduction to Python. Randall Romero Aguilar, PhD II Semestre 2018 Last updated: July 12, 2018 Lecture 0 Introduction to Python Randall Romero Aguilar, PhD II Semestre 2018 Last updated: July 12, 2018 Universidad de Costa Rica SP6534 - Economía Computacional Table of contents 1. Getting Python and

More information

Worksheet 6: Basic Methods Methods The Format Method Formatting Floats Formatting Different Types Formatting Keywords

Worksheet 6: Basic Methods Methods The Format Method Formatting Floats Formatting Different Types Formatting Keywords Worksheet 1: Introductory Exercises Turtle Programming Calculations The Print Function Comments Syntax Semantics Strings Concatenation Quotation Marks Types Variables Restrictions on Variable Names Long

More information

Introduction to Python Part 1

Introduction to Python Part 1 Introduction to Python Part 1 v0.2 Brian Gregor Research Computing Services Information Services & Technology RCS Team and Expertise Our Team Scientific Programmers Systems Administrators Graphics/Visualization

More information

PRG PROGRAMMING ESSENTIALS. Lecture 2 Program flow, Conditionals, Loops

PRG PROGRAMMING ESSENTIALS. Lecture 2 Program flow, Conditionals, Loops PRG PROGRAMMING ESSENTIALS 1 Lecture 2 Program flow, Conditionals, Loops https://cw.fel.cvut.cz/wiki/courses/be5b33prg/start Michal Reinštein Czech Technical University in Prague, Faculty of Electrical

More information

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration STATS 507 Data Analysis in Python Lecture 2: Functions, Conditionals, Recursion and Iteration Functions in Python We ve already seen examples of functions: e.g., type()and print() Function calls take the

More information

C++ for Python Programmers

C++ for Python Programmers C++ for Python Programmers Adapted from a document by Rich Enbody & Bill Punch of Michigan State University Purpose of this document This document is a brief introduction to C++ for Python programmers

More information

Python Workshop. January 18, Chaitanya Talnikar. Saket Choudhary

Python Workshop. January 18, Chaitanya Talnikar. Saket Choudhary Chaitanya Talnikar Saket Choudhary January 18, 2012 Python Named after this : Python Slide 1 was a joke! Python Slide 1 was a joke! Python : Conceived in late 1980s by Guido van Rossum as a successor to

More information

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s Intro to Python Python Getting increasingly more common Designed to have intuitive and lightweight syntax In this class, we will be using Python 3.x Python 2.x is still very popular, and the differences

More information

Introduction to Computer Vision Laboratories

Introduction to Computer Vision Laboratories Introduction to Computer Vision Laboratories Antonino Furnari furnari@dmi.unict.it www.dmi.unict.it/~furnari/ Computer Vision Laboratories Format: practical session + questions and homeworks. Material

More information

Lecture 1: Introduction to Python

Lecture 1: Introduction to Python Hendrik Weimer Institute for Theoretical Physics, Leibniz University Hannover Quantum Physics with Python, 04 April 2016 Goals of this course Learn to use the Python language for physics problems Master

More information

Key Differences Between Python and Java

Key Differences Between Python and Java Python Python supports many (but not all) aspects of object-oriented programming; but it is possible to write a Python program without making any use of OO concepts. Python is designed to be used interpretively.

More information

Python Programming, bridging course 2011

Python Programming, bridging course 2011 Python Programming, bridging course 2011 About the course Few lectures Focus on programming practice Slides on the homepage No course book. Using online resources instead. Online Python resources http://www.python.org/

More information

CIS192 Python Programming. Robert Rand. August 27, 2015

CIS192 Python Programming. Robert Rand. August 27, 2015 CIS192 Python Programming Introduction Robert Rand University of Pennsylvania August 27, 2015 Robert Rand (University of Pennsylvania) CIS 192 August 27, 2015 1 / 30 Outline 1 Logistics Grading Office

More information

Part IV. More on Python. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26,

Part IV. More on Python. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26, Part IV More on Python Compact Course @ Max-Planck, February 16-26, 2015 36 More on Strings Special string methods (excerpt) s = " Frodo and Sam and Bilbo " s. islower () s. isupper () s. startswith ("

More information

STATS 507 Data Analysis in Python. Lecture 0: Introduction and Administrivia

STATS 507 Data Analysis in Python. Lecture 0: Introduction and Administrivia STATS 507 Data Analysis in Python Lecture 0: Introduction and Administrivia Data science has completely changed our world Course goals Establish a broad background in Python programming Prepare you for

More information

Introduction to programming with Python

Introduction to programming with Python Introduction to programming with Python Ing. Lelio Campanile 1/61 Main Goal - Introduce you to programming - introduce you to the most essential feature of python programming 2/61 Before to start The name

More information

Table of Contents. Preface... xxi

Table of Contents. Preface... xxi Table of Contents Preface... xxi Chapter 1: Introduction to Python... 1 Python... 2 Features of Python... 3 Execution of a Python Program... 7 Viewing the Byte Code... 9 Flavors of Python... 10 Python

More information

The Python interpreter

The Python interpreter The Python interpreter Daniel Winklehner, Remi Lehe US Particle Accelerator School (USPAS) Summer Session Self-Consistent Simulations of Beam and Plasma Systems S. M. Lund, J.-L. Vay, D. Bruhwiler, R.

More information

Python review. 1 Python basics. References. CS 234 Naomi Nishimura

Python review. 1 Python basics. References. CS 234 Naomi Nishimura Python review CS 234 Naomi Nishimura The sections below indicate Python material, the degree to which it will be used in the course, and various resources you can use to review the material. You are not

More information

Senthil Kumaran S

Senthil Kumaran S Senthil Kumaran S http://www.stylesen.org/ Agenda History Basics Control Flow Functions Modules History What is Python? Python is a general purpose, object-oriented, high level, interpreted language Created

More information

Python Programming. Hans-Petter Halvorsen.

Python Programming. Hans-Petter Halvorsen. Python Programming Hans-Petter Halvorsen https://www.halvorsen.blog Python Programming Python Programming Hans-Petter Halvorsen 2018 Python Programming c Hans-Petter Halvorsen December 20, 2018 1 Preface

More information

Accelerating Information Technology Innovation

Accelerating Information Technology Innovation Accelerating Information Technology Innovation http://aiti.mit.edu/program/philippines-summer-2012/ Philippines Summer 2012 Lecture 1 Introduction to Python June 19, 2012 Agenda About the Course What is

More information

Python for Scientists

Python for Scientists High level programming language with an emphasis on easy to read and easy to write code Includes an extensive standard library We use version 3 History: Exists since 1991 Python 3: December 2008 General

More information

FIT9133 Module 1: Introduction to Algorithms and Python Programming Basics

FIT9133 Module 1: Introduction to Algorithms and Python Programming Basics FIT9133 Module 1: Introduction to Algorithms and Python Programming Basics FIT9133 Foundations of Programming in Python Jojo Wong i FIT9133 Module 1: Introduction to Algorithms and Python Programming Basics

More information

Data type built into Python. Dictionaries are sometimes found in other languages as associative memories or associative arrays.

Data type built into Python. Dictionaries are sometimes found in other languages as associative memories or associative arrays. NETB 329 Lecture 4 Data Structures in Python Dictionaries Data type built into Python. Dictionaries are sometimes found in other languages as associative memories or associative arrays. 1 of 70 Unlike

More information

PYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s

PYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s PYTHON FO R K I D S A P l ay f u l I n t r o d u c t i o n to P r o g r a m m i n g Jason R. Briggs Index Symbols and Numbers + (addition operator), 17 \ (backslash) to separate lines of code, 235 in strings,

More information

Shell / Python Tutorial. CS279 Autumn 2017 Rishi Bedi

Shell / Python Tutorial. CS279 Autumn 2017 Rishi Bedi Shell / Python Tutorial CS279 Autumn 2017 Rishi Bedi Shell (== console, == terminal, == command prompt) You might also hear it called bash, which is the most widely used shell program macos Windows 10+

More information

What Version Number to Install

What Version Number to Install A Python Primer This chapter provides a quick overview of the Python language. The goal in this chapter is not to teach you the Python language excellent books have been written on that subject, such as

More information

Introduction to Python. Didzis Gosko

Introduction to Python. Didzis Gosko Introduction to Python Didzis Gosko Scripting language From Wikipedia: A scripting language or script language is a programming language that supports scripts, programs written for a special run-time environment

More information

Python for Earth Scientists

Python for Earth Scientists Python for Earth Scientists Andrew Walker andrew.walker@bris.ac.uk Python is: A dynamic, interpreted programming language. Python is: A dynamic, interpreted programming language. Data Source code Object

More information

DSC 201: Data Analysis & Visualization

DSC 201: Data Analysis & Visualization DSC 201: Data Analysis & Visualization Arrays Dr. David Koop Class Example class Rectangle: def init (self, x, y, w, h): self.x = x self.y = y self.w = w self.h = h def set_corner(self, x, y): self.x =

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer i About the Tutorial Project is a comprehensive software suite for interactive computing, that includes various packages such as Notebook, QtConsole, nbviewer, Lab. This tutorial gives you an exhaustive

More information

Python Basics. Lecture and Lab 5 Day Course. Python Basics

Python Basics. Lecture and Lab 5 Day Course. Python Basics Python Basics Lecture and Lab 5 Day Course Course Overview Python, is an interpreted, object-oriented, high-level language that can get work done in a hurry. A tool that can improve all professionals ability

More information

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

Certified Data Science with Python Professional VS-1442

Certified Data Science with Python Professional VS-1442 Certified Data Science with Python Professional VS-1442 Certified Data Science with Python Professional Certified Data Science with Python Professional Certification Code VS-1442 Data science has become

More information

CIS192: Python Programming

CIS192: Python Programming CIS192: Python Programming Introduction Harry Smith University of Pennsylvania January 18, 2017 Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 1 / 34 Outline 1 Logistics Rooms

More information

Accelerating Information Technology Innovation

Accelerating Information Technology Innovation Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lesson 1 Introduction to Python Agenda What is Python? and Why Python? Basic Syntax Strings User Input Useful

More information

tutorial : modeling synaptic plasticity

tutorial : modeling synaptic plasticity tutorial : modeling synaptic plasticity Computational Neuroscience by the Mediterranean Winter School, Jan 20th, 2016 Michael Graupner Université Paris Descartes CNRS UMR 8118, Paris, France michael.graupner@parisdescartes.fr

More information

Hacettepe University Computer Engineering Department. Programming in. BBM103 Introduction to Programming Lab 1 Week 4. Fall 2018

Hacettepe University Computer Engineering Department. Programming in. BBM103 Introduction to Programming Lab 1 Week 4. Fall 2018 Hacettepe University Computer Engineering Department Programming in BBM103 Introduction to Programming Lab 1 Week 4 Fall 2018 Install PyCharm Download Link : https://www.jetbrains.com/pycharm-edu/download/#section=windows

More information

MLCV 182: Practical session 1 Ron Shapira Weber Computer Science, Ben-Gurion University

MLCV 182: Practical session 1 Ron Shapira Weber Computer Science, Ben-Gurion University MLCV 182: Practical session 1 Ron Shapira Weber Computer Science, Ben-Gurion University Getting Started There are two different versions of Python being supported at the moment, 2.7 and 3.6. For compatibility

More information

python 01 September 16, 2016

python 01 September 16, 2016 python 01 September 16, 2016 1 Introduction to Python adapted from Steve Phelps lectures - (http://sphelps.net) 2 Python is interpreted Python is an interpreted language (Java and C are not). In [1]: 7

More information

Visualize ComplexCities

Visualize ComplexCities Introduction to Python Chair of Information Architecture ETH Zürich February 22, 2013 First Steps Python Basics Conditionals Statements Loops User Input Functions Programming? Programming is the interaction

More information

A. Python Crash Course

A. Python Crash Course A. Python Crash Course Agenda A.1 Installing Python & Co A.2 Basics A.3 Data Types A.4 Conditions A.5 Loops A.6 Functions A.7 I/O A.8 OLS with Python 2 A.1 Installing Python & Co You can download and install

More information

Introduction to Mathematical and Scientific Programming TUTORIAL WEEK 1 (MATH 1MP3) Winter 2019

Introduction to Mathematical and Scientific Programming TUTORIAL WEEK 1 (MATH 1MP3) Winter 2019 TUTORIAL WEEK 1 Introduction to Mathematical and Scientific Programming (MATH 1MP3) Winter 2019 Important Links 1- The Course Website https://ms.mcmaster.ca/~matt/1mp3.html 2- Python https://www.python.org/downloads/

More information

Intelligente Datenanalyse Intelligent Data Analysis

Intelligente Datenanalyse Intelligent Data Analysis Universität Potsdam Institut für Informatik Lehrstuhl Maschinelles Lernen Intelligent Data Analysis Tobias Scheffer, Gerrit Gruben, Nuno Marquez Plan for this lecture Introduction to Python Main goal is

More information

Episode 1 Using the Interpreter

Episode 1 Using the Interpreter Episode 1 Using the Interpreter Anaconda We recommend, but do not require, the Anaconda distribution from Continuum Analytics (www.continuum.io). An overview is available at https://docs.continuum.io/anaconda.

More information

DaMPL. Language Reference Manual. Henrique Grando

DaMPL. Language Reference Manual. Henrique Grando DaMPL Language Reference Manual Bernardo Abreu Felipe Rocha Henrique Grando Hugo Sousa bd2440 flt2107 hp2409 ha2398 Contents 1. Getting Started... 4 2. Syntax Notations... 4 3. Lexical Conventions... 4

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

LECTURE 1. Getting Started with Python

LECTURE 1. Getting Started with Python LECTURE 1 Getting Started with Python ABOUT PYTHON Development started in the 1980 s by Guido van Rossum. Only became popular in the last decade or so. Python 2.x currently dominates, but Python 3.x is

More information

Collections. Lists, Tuples, Sets, Dictionaries

Collections. Lists, Tuples, Sets, Dictionaries Collections Lists, Tuples, Sets, Dictionaries Homework notes Homework 1 grades on canvas People mostly lost points for not reading the document carefully Didn t play again Didn t use Y/N for playing again

More information

Introduction to Python

Introduction to Python Introduction to Python خانه ریاضیات اصفهان فرزانه کاظمی زمستان 93 1 Why Python? Python is free. Python easy to lean and use. Reduce time and length of coding. Huge standard library Simple (Python code

More information

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Tools : The Java Compiler. The Java Interpreter. The Java Debugger Tools : The Java Compiler javac [ options ] filename.java... -depend: Causes recompilation of class files on which the source files given as command line arguments recursively depend. -O: Optimizes code,

More information

Introduction to Python, Cplex and Gurobi

Introduction to Python, Cplex and Gurobi Introduction to Python, Cplex and Gurobi Introduction Python is a widely used, high level programming language designed by Guido van Rossum and released on 1991. Two stable releases: Python 2.7 Python

More information

CS150 Sample Final Solution

CS150 Sample Final Solution CS150 Sample Final Solution Name: Section: A / B Date: Start time: End time: Honor Code: Signature: This exam is closed book, closed notes, closed computer, closed calculator, etc. You may only use (1)

More information

CS150 Sample Final. Name: Section: A / B

CS150 Sample Final. Name: Section: A / B CS150 Sample Final Name: Section: A / B Date: Start time: End time: Honor Code: Signature: This exam is closed book, closed notes, closed computer, closed calculator, etc. You may only use (1) the final

More information

STSCI Python Introduction. Class URL

STSCI Python Introduction. Class URL STSCI Python Introduction Class 2 Jim Hare Class URL www.pst.stsci.edu/~hare Each Class Presentation Homework suggestions Example files to download Links to sites by each class and in general I will try

More information