Introduction to Python



Similar documents
Welcome to Introduction to programming in Python

Computational Mathematics with Python

Computational Mathematics with Python

Exercise 1: Python Language Basics

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.

Introduction to Python

Computational Mathematics with Python

Introduction to Python

Modeling with Python

Exercise 4 Learning Python language fundamentals

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

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

Java Crash Course Part I

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

ESPResSo Summer School 2012

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June Dr.-Ing.

Microsoft Windows PowerShell v2 For Administrators

Beyond the Mouse A Short Course on Programming

NLP Programming Tutorial 0 - Programming Basics

Computer Science for San Francisco Youth

Simulation Tools. Python for MATLAB Users I. Claus Führer. Automn Claus Führer Simulation Tools Automn / 65

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Python programming guide for Earth Scientists. Maarten J. Waterloo and Vincent E.A. Post

BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering

13 File Output and Input

Programming Languages & Tools

Introduction to Python

Some programming experience in a high-level structured programming language is recommended.

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

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

The C Programming Language course syllabus associate level

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

Visual Basic Programming. An Introduction

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

Informatica e Sistemi in Tempo Reale

Introduction. Chapter 1

CLC Server Command Line Tools USER MANUAL

Introduction to the course, Eclipse and Python

How To Use Query Console

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

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

Python for Scientific Computing.

Exploring Algorithms with Python

Computer Programming I & II*

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class

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

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

6.170 Tutorial 3 - Ruby Basics

A Java array is kind of like a credit card holder Sleeves to put credit cards in

VHDL Test Bench Tutorial

Lecture 9 Chrome Extensions

STEP 0: OPEN UP THE PYTHON EDITOR. If python is on your computer already, it's time to get started. On Windows, find IDLE in the start menu.

Creating a Java application using Perfect Developer and the Java Develo...

AMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables

Ruby - A Brief History

Invitation to Ezhil : A Tamil Programming Language for Early Computer-Science Education 07/10/13

CP Lab 2: Writing programs for simple arithmetic problems

Python Loops and String Manipulation

Appendix: Tutorial Introduction to MATLAB

PYTHON Basics

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT,

CPSC 226 Lab Nine Fall 2015

CMSC Fundamentals of Computer Programming II (C++)

HPC Wales Skills Academy Course Catalogue 2015

Illustration 1: Diagram of program function and data flow

Python Basics. S.R. Doty. August 27, Preliminaries What is Python? Installation and documentation... 4

Introduction to Java

Code Estimation Tools Directions for a Services Engagement

COSC282 BIG DATA ANALYTICS FALL 2015 LECTURE 2 - SEP 9

CS 1133, LAB 2: FUNCTIONS AND TESTING

Android Based Appointment Scheduler and Location Helper using file operation

Sources: On the Web: Slides will be available on:

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

Beginning to Program Python

An Incomplete C++ Primer. University of Wyoming MA 5310

1001ICT Introduction To Programming Lecture Notes

CS 103 Lab Linux and Virtual Machines

Introduction to Python for Text Analysis

Python Lists and Loops

Crash Dive into Python

D is for Science. John Colvin

FEEG Applied Programming 5 - Tutorial Session

Programmierpraktikum

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

The BSN Hardware and Software Platform: Enabling Easy Development of Body Sensor Network Applications

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

Cobol. By: Steven Conner. COBOL, COmmon Business Oriented Language, one of the. oldest programming languages, was designed in the last six

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction

Introduction to Programming with Xojo

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

Visual Basic. murach's TRAINING & REFERENCE

CRASH COURSE PYTHON. Het begint met een idee

USE OF PYTHON AS A SATELLITE OPERATIONS AND TESTING AUTOMATION LANGUAGE

Using Dedicated Servers from the game

Introduction to CloudScript

A Tutorial on installing and using Eclipse

Yun Shield Quick Start Guide VERSION: 1.0 Version Description Date 1.0 Release 2014-Jul-08 Yun Shield Quick Start Guide 1 / 14

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

Transcription:

Introduction to Python Sophia Bethany Coban Problem Solving By Computer March 26, 2014

Introduction to Python Python is a general-purpose, high-level programming language. It offers readable codes, and its syntax allows us to write programs in fewer lines, compared to C/C++. There are 2 main version branches of Python: * 2.x branch * 3.x branch and these versions are incompatible! However, the latest major version of 2.x (2.7) is close to 3.x. Python 2.6 or 2.7 is a good place to start but Python 3.x is more important! So make sure you learn the differences between them. Sophia Bethany Coban Problem Solving By Computer 2/23

Introduction to Python Python is a general-purpose, high-level programming language. It offers readable codes, and its syntax allows us to write programs in fewer lines, compared to C/C++. There are 2 main version branches of Python: * 2.x branch * 3.x branch and these versions are incompatible! However, the latest major version of 2.x (2.7) is close to 3.x. Python 2.6 or 2.7 is a good place to start but Python 3.x is more important! So make sure you learn the differences between them. Sophia Bethany Coban Problem Solving By Computer 2/23

Introduction to Python Python is a general-purpose, high-level programming language. It offers readable codes, and its syntax allows us to write programs in fewer lines, compared to C/C++. There are 2 main version branches of Python: * 2.x branch * 3.x branch and these versions are incompatible! However, the latest major version of 2.x (2.7) is close to 3.x. Python 2.6 or 2.7 is a good place to start but Python 3.x is more important! So make sure you learn the differences between them. Sophia Bethany Coban Problem Solving By Computer 2/23

Introduction to Python Python is a general-purpose, high-level programming language. It offers readable codes, and its syntax allows us to write programs in fewer lines, compared to C/C++. There are 2 main version branches of Python: * 2.x branch * 3.x branch and these versions are incompatible! However, the latest major version of 2.x (2.7) is close to 3.x. Python 2.6 or 2.7 is a good place to start but Python 3.x is more important! So make sure you learn the differences between them. Sophia Bethany Coban Problem Solving By Computer 2/23

Introduction to Python Python is a general-purpose, high-level programming language. It offers readable codes, and its syntax allows us to write programs in fewer lines, compared to C/C++. There are 2 main version branches of Python: * 2.x branch * 3.x branch and these versions are incompatible! However, the latest major version of 2.x (2.7) is close to 3.x. Python 2.6 or 2.7 is a good place to start but Python 3.x is more important! So make sure you learn the differences between them. Sophia Bethany Coban Problem Solving By Computer 2/23

Introduction to Python Python is a general-purpose, high-level programming language. It offers readable codes, and its syntax allows us to write programs in fewer lines, compared to C/C++. There are 2 main version branches of Python: * 2.x branch * 3.x branch and these versions are incompatible! However, the latest major version of 2.x (2.7) is close to 3.x. Python 2.6 or 2.7 is a good place to start but Python 3.x is more important! So make sure you learn the differences between them. Sophia Bethany Coban Problem Solving By Computer 2/23

About IPython Python lacks a shiny GUI (compared to MATLAB). BUT there exists a solution called IPython! IPython notebook is an interface that looks a lot like a Mathematica notebook. It has quickly became the standard as an interactive, numerical computing tool for Python. We will not go into how IPython works but you are welcome to experiment with it as you like. The Windows computers in ATB do not have IPython (Anaconda recommended) but it can be downloaded via http://ipython.org/install.html (the download and the set up take about 3 minutes). Sophia Bethany Coban Problem Solving By Computer 3/23

About IPython Python lacks a shiny GUI (compared to MATLAB). BUT there exists a solution called IPython! IPython notebook is an interface that looks a lot like a Mathematica notebook. It has quickly became the standard as an interactive, numerical computing tool for Python. We will not go into how IPython works but you are welcome to experiment with it as you like. The Windows computers in ATB do not have IPython (Anaconda recommended) but it can be downloaded via http://ipython.org/install.html (the download and the set up take about 3 minutes). Sophia Bethany Coban Problem Solving By Computer 3/23

About IPython Python lacks a shiny GUI (compared to MATLAB). BUT there exists a solution called IPython! IPython notebook is an interface that looks a lot like a Mathematica notebook. It has quickly became the standard as an interactive, numerical computing tool for Python. We will not go into how IPython works but you are welcome to experiment with it as you like. The Windows computers in ATB do not have IPython (Anaconda recommended) but it can be downloaded via http://ipython.org/install.html (the download and the set up take about 3 minutes). Sophia Bethany Coban Problem Solving By Computer 3/23

About IPython Python lacks a shiny GUI (compared to MATLAB). BUT there exists a solution called IPython! IPython notebook is an interface that looks a lot like a Mathematica notebook. It has quickly became the standard as an interactive, numerical computing tool for Python. We will not go into how IPython works but you are welcome to experiment with it as you like. The Windows computers in ATB do not have IPython (Anaconda recommended) but it can be downloaded via http://ipython.org/install.html (the download and the set up take about 3 minutes). Sophia Bethany Coban Problem Solving By Computer 3/23

About IPython Python lacks a shiny GUI (compared to MATLAB). BUT there exists a solution called IPython! IPython notebook is an interface that looks a lot like a Mathematica notebook. It has quickly became the standard as an interactive, numerical computing tool for Python. We will not go into how IPython works but you are welcome to experiment with it as you like. The Windows computers in ATB do not have IPython (Anaconda recommended) but it can be downloaded via http://ipython.org/install.html (the download and the set up take about 3 minutes). Sophia Bethany Coban Problem Solving By Computer 3/23

Why Python? Python is easy to read! A good transition between a language like MATLAB to more C/C++ and scripting languages. It is free and open source, which is why most companies prefer Python over MATLAB. Something else to add on your CV!! Sophia Bethany Coban Problem Solving By Computer 4/23

Why Python? Python is easy to read! A good transition between a language like MATLAB to more C/C++ and scripting languages. It is free and open source, which is why most companies prefer Python over MATLAB. Something else to add on your CV!! Sophia Bethany Coban Problem Solving By Computer 4/23

Why Python? Python is easy to read! A good transition between a language like MATLAB to more C/C++ and scripting languages. It is free and open source, which is why most companies prefer Python over MATLAB. Something else to add on your CV!! Sophia Bethany Coban Problem Solving By Computer 4/23

Why Python? Python is easy to read! A good transition between a language like MATLAB to more C/C++ and scripting languages. It is free and open source, which is why most companies prefer Python over MATLAB. Something else to add on your CV!! Sophia Bethany Coban Problem Solving By Computer 4/23

Learning Objectives In these slides, we will go through Basic maths and string operations, Variables, their types and lists (arrays), If statements, for/while loops, functions and Modules, packages, and how to use them. But most of all, the one thing we need to learn today is how important TABBING is in Python. We will give examples both in MATLAB and Python, and compare the codes. Sophia Bethany Coban Problem Solving By Computer 5/23

Learning Objectives In these slides, we will go through Basic maths and string operations, Variables, their types and lists (arrays), If statements, for/while loops, functions and Modules, packages, and how to use them. But most of all, the one thing we need to learn today is how important TABBING is in Python. We will give examples both in MATLAB and Python, and compare the codes. Sophia Bethany Coban Problem Solving By Computer 5/23

Learning Objectives In these slides, we will go through Basic maths and string operations, Variables, their types and lists (arrays), If statements, for/while loops, functions and Modules, packages, and how to use them. But most of all, the one thing we need to learn today is how important TABBING is in Python. We will give examples both in MATLAB and Python, and compare the codes. Sophia Bethany Coban Problem Solving By Computer 5/23

Learning Objectives In these slides, we will go through Basic maths and string operations, Variables, their types and lists (arrays), If statements, for/while loops, functions and Modules, packages, and how to use them. But most of all, the one thing we need to learn today is how important TABBING is in Python. We will give examples both in MATLAB and Python, and compare the codes. Sophia Bethany Coban Problem Solving By Computer 5/23

Learning Objectives In these slides, we will go through Basic maths and string operations, Variables, their types and lists (arrays), If statements, for/while loops, functions and Modules, packages, and how to use them. But most of all, the one thing we need to learn today is how important TABBING is in Python. We will give examples both in MATLAB and Python, and compare the codes. Sophia Bethany Coban Problem Solving By Computer 5/23

Learning Objectives In these slides, we will go through Basic maths and string operations, Variables, their types and lists (arrays), If statements, for/while loops, functions and Modules, packages, and how to use them. But most of all, the one thing we need to learn today is how important TABBING is in Python. We will give examples both in MATLAB and Python, and compare the codes. Sophia Bethany Coban Problem Solving By Computer 5/23

Learning Objectives In these slides, we will go through Basic maths and string operations, Variables, their types and lists (arrays), If statements, for/while loops, functions and Modules, packages, and how to use them. But most of all, the one thing we need to learn today is how important TABBING is in Python. We will give examples both in MATLAB and Python, and compare the codes. Sophia Bethany Coban Problem Solving By Computer 5/23

Running Python - Mac OSX In these slides, we either run Python in a Terminal (similar to using MATLAB s command window), or use a text editor for the code and run the script in the Terminal for an output: Sophia Bethany Coban Problem Solving By Computer 6/23

Running Python - Mac OSX In these slides, we either run Python in a Terminal (similar to using MATLAB s command window), or use a text editor for the code and run the script in the Terminal for an output: Python in Terminal Sophia Bethany Coban Problem Solving By Computer 6/23

Running Python - Mac OSX In these slides, we either run Python in a Terminal (similar to using MATLAB s command window), or use a text editor for the code and run the script in the Terminal for an output: Python with a text editor (TextWrangler) Sophia Bethany Coban Problem Solving By Computer 6/23

Running Python - Linux Same steps can be taken to run Python in Linux as well (not surprising): Sophia Bethany Coban Problem Solving By Computer 7/23

Running Python - Linux Same steps can be taken to run Python in Linux as well (not surprising): Python in Terminal Sophia Bethany Coban Problem Solving By Computer 7/23

Running Python - Linux Same steps can be taken to run Python in Linux as well (not surprising): Python with a text editor (Gedit) Sophia Bethany Coban Problem Solving By Computer 7/23

Running Python - Windows In the ATB clusters, run Python via Start>Python IDLE. This program is similar to MATLAB in a sense that it has its own Editor and debug mode. Python Shell Sophia Bethany Coban Problem Solving By Computer 8/23

Running Python - Windows In the ATB clusters, run Python via Start>Python IDLE. This program is similar to MATLAB in a sense that it has its own Editor and debug mode. IPython QT Console Sophia Bethany Coban Problem Solving By Computer 8/23

Basic Operations Python (as any other language) has addition, subtraction, multiplication and division implemented. Sophia Bethany Coban Problem Solving By Computer 9/23

Basic Operations Python (as any other language) has addition, subtraction, multiplication and division implemented. If we were to calculate c = 2 + 5 3 6/9, would Python follow the correct order? Sophia Bethany Coban Problem Solving By Computer 9/23

Basic Operations Python (as any other language) has addition, subtraction, multiplication and division implemented. If we were to calculate c = 2 + 5 3 6/9, would Python follow the correct order? MATLAB Python Sophia Bethany Coban Problem Solving By Computer 9/23

Variables and Types Every variable in Python is an object and you do not need to declare their type before using them (something we do in C/C++). Below would be declared as an integer in Python: >>> n int = 5 This would be a floating point number: >>> n float = 5.0 We also have strings declared in single or double quotation marks: >>> a string = Hello World! Finding type of a variable: Sophia Bethany Coban Problem Solving By Computer 10/23

String Operations You can do a lot with strings in Python. Sophia Bethany Coban Problem Solving By Computer 11/23

String Operations You can do a lot with strings in Python. Print can also work as fprintf: Sophia Bethany Coban Problem Solving By Computer 11/23

String Operations You can do a lot with strings in Python. Print can also work as fprintf: MATLAB Python Sophia Bethany Coban Problem Solving By Computer 11/23

String Operations You can add two strings together: MATLAB Python or multiply a string with a number: MATLAB Python There is a lot you can do with strings in Python! Sophia Bethany Coban Problem Solving By Computer 12/23

String Operations You can add two strings together: MATLAB Python or multiply a string with a number: MATLAB Python There is a lot you can do with strings in Python! Sophia Bethany Coban Problem Solving By Computer 12/23

Lists Lists are similar to arrays or vectors but they can contain variables of any type. We can declare a list in the following way: >>> mylist = [1, 2, 3] or initialise as empty, and append elements individually: >>> mylist = [ ] >>> mylist.append( Hello! ) Let us try appending a string to a list of integers: Sophia Bethany Coban Problem Solving By Computer 13/23

Lists To access a specific element in a list, we use >>> print = mylist[< index >] BUT indexing starts from 0 in Python (like in C/C++ but not in MATLAB)! Sophia Bethany Coban Problem Solving By Computer 14/23

Conditions and If Statements We have the boolean values True and False to evaluate conditions in Python (same as in MATLAB): Sophia Bethany Coban Problem Solving By Computer 15/23

Conditions and If Statements We have the boolean values True and False to evaluate conditions in Python (same as in MATLAB): The syntax for if statemets is a little different: MATLAB Python Sophia Bethany Coban Problem Solving By Computer 15/23

Conditions and If Statements We have the boolean values True and False to evaluate conditions in Python (same as in MATLAB): The syntax for if statemets is a little different: MATLAB Python Sophia Bethany Coban Problem Solving By Computer 15/23

Conditions and If Statements We have the boolean values True and False to evaluate conditions in Python (same as in MATLAB): The syntax for if statemets is a little different: MATLAB Python Of course in an editor, you would not have to press enter for output BUT you would have to put the tab! Sophia Bethany Coban Problem Solving By Computer 15/23

Conditions and If Statements For when we have multiple conditions, we use and and or (much like && and in MATLAB). We also have not for inverting the boolean value similar to = (not equal) in MATLAB. When we have more than one statement to check? We use if/elseif in MATLAB but in Python, this is if/elif. Sophia Bethany Coban Problem Solving By Computer 16/23

Conditions and If Statements CODE: For when we have multiple conditions, we use and and or (much like && and in MATLAB). We also have not for inverting the boolean value similar to = (not equal) in MATLAB. When we have more than one statement to check? We use if/elseif in MATLAB but in Python, this is if/elif. Output?? Sophia Bethany Coban Problem Solving By Computer 16/23

Conditions and If Statements CODE: For when we have multiple conditions, we use and and or (much like && and in MATLAB). We also have not for inverting the boolean value similar to = (not equal) in MATLAB. When we have more than one statement to check? We use if/elseif in MATLAB but in Python, this is if/elif. Output?? Sophia Bethany Coban Problem Solving By Computer 16/23

Loops Just as in MATLAB, we have two different types of looping in Python: For and While. The syntax is very similar to the if statements: Put a colon after the for/while <statement> line, and Use tabs to continue with the loop or go back a tab to end the loop. Sophia Bethany Coban Problem Solving By Computer 17/23

Loops Just as in MATLAB, we have two different types of looping in Python: For and While. The syntax is very similar to the if statements: Put a colon after the for/while <statement> line, and Use tabs to continue with the loop or go back a tab to end the loop. MATLAB Python Sophia Bethany Coban Problem Solving By Computer 17/23

Loops Just as in MATLAB, we have two different types of looping in Python: For and While. The syntax is very similar to the if statements: Put a colon after the for/while <statement> line, and Use tabs to continue with the loop or go back a tab to end the loop. MATLAB Python Sophia Bethany Coban Problem Solving By Computer 17/23

Loops Below is an example of a while loop (and more tabbing!) in Python. Sophia Bethany Coban Problem Solving By Computer 18/23

Loops Below is an example of a while loop (and more tabbing!) in Python. MATLAB Python Sophia Bethany Coban Problem Solving By Computer 18/23

Loops Below is an example of a while loop (and more tabbing!) in Python. MATLAB Python Sophia Bethany Coban Problem Solving By Computer 18/23

Loops We also have Break and Continue in Python, which work exactly the same way as in MATLAB (and in C/C++): Code (note they are now in.m and.py scripts) Sophia Bethany Coban Problem Solving By Computer 19/23

Loops We also have Break and Continue in Python, which work exactly the same way as in MATLAB (and in C/C++): Code (note they are now in.m and.py scripts) MATLAB Python Sophia Bethany Coban Problem Solving By Computer 19/23

Loops We also have Break and Continue in Python, which work exactly the same way as in MATLAB (and in C/C++): Code (note they are now in.m and.py scripts) MATLAB Python Output?? Sophia Bethany Coban Problem Solving By Computer 19/23

Loops We also have Break and Continue in Python, which work exactly the same way as in MATLAB (and in C/C++): Code (note they are now in.m and.py scripts) MATLAB Python Output?? MATLAB Python Sophia Bethany Coban Problem Solving By Computer 19/23

Loops We also have Break and Continue in Python, which work exactly the same way as in MATLAB (and in C/C++): Code (note they are now in.m and.py scripts) MATLAB Python Notice we used range(1,6) for t = 1:5 This is the range from 1 to 6, (with 6 not included). We could have also used xrange. (HW) Learn the difference between range and xrange! Sophia Bethany Coban Problem Solving By Computer 19/23

Functions We create and call functions in the following ways. Sophia Bethany Coban Problem Solving By Computer 20/23

Functions We create and call functions in the following ways. A function without any input arguments: MATLAB Python Output: Output: Sophia Bethany Coban Problem Solving By Computer 20/23

Functions We create and call functions in the following ways. A function with one input and one output argument: MATLAB Python Output: Output: Sophia Bethany Coban Problem Solving By Computer 20/23

Functions We create and call functions in the following ways. A function with one input and one output argument: MATLAB Python Output: Output: Sophia Bethany Coban Problem Solving By Computer 20/23

Functions We create and call functions in the following ways. A function with multiple input and output arguments: MATLAB Python Sophia Bethany Coban Problem Solving By Computer 20/23

Functions We create and call functions in the following ways. A function with multiple input and output arguments: MATLAB Output Python Output Sophia Bethany Coban Problem Solving By Computer 20/23

Modules and Packages How to call a function in a different script? Use import! Sophia Bethany Coban Problem Solving By Computer 21/23

Modules and Packages How to call a function in a different script? Use import! Import is used to call modules. Sophia Bethany Coban Problem Solving By Computer 21/23

Modules and Packages How to call a function in a different script? Use import! Import is used to call modules. A module is a.py script with a number of functions. Sophia Bethany Coban Problem Solving By Computer 21/23

Modules and Packages How to call a function in a different script? Use import! Import is used to call modules. A module is a.py script with a number of functions. Let us call the previous function we used to add and compare numbers: Sophia Bethany Coban Problem Solving By Computer 21/23

Modules and Packages How to call a function in a different script? Use import! Calling functions in another.py script: Output: Sophia Bethany Coban Problem Solving By Computer 21/23

Modules and Packages How to call a function in a different script? Use import! Calling functions in another.py script: Output: Sophia Bethany Coban Problem Solving By Computer 21/23

Modules and Packages How to call a function in a different script? Use import! Import is used to call modules. A module is a.py script with a number of functions. We can use dir to print the functions in the imported module: Sophia Bethany Coban Problem Solving By Computer 21/23

Modules and Packages How to call a function in a different script? Use import! Import is used to call modules. A module is a.py script with a number of functions. We can use dir to print the functions in the imported module: Printing functions in a module: Sophia Bethany Coban Problem Solving By Computer 21/23

Modules and Packages How to call a function in a different script? Use import! Import is used to call modules. A module is a.py script with a number of functions. We can use dir to print the functions in the imported module. We can also use help to learn about the functions in the imported module: Sophia Bethany Coban Problem Solving By Computer 21/23

Modules and Packages How to call a function in a different script? Use import! Import is used to call modules. We can use dir to print the functions in the imported module. We can also use help to learn about the functions in the imported module: Using help on functions in a module: Sophia Bethany Coban Problem Solving By Computer 21/23

Modules and Packages How to call a function in a different script? Use import! Import is used to call modules. A module is a.py script with a number of functions. We can use dir to print the functions in the imported module. We can also use help to learn about the functions in the imported module. Packages are a collection of modules put together (can be useful for different projects). (HW) Find out how to create packages! Sophia Bethany Coban Problem Solving By Computer 21/23

Closing Notes Learning a new coding language often means a different way of thinking. Python is available in all platforms and running scripts is very common in/for all the devices, so it is very well integrated. We would be very impressed with you for being able to code in Python! You must remember that you would be more independent in finding solutions to your problems if you choose to code in Python. Don t be put off by the lack of a fancy gui and remember, practice makes perfect. Sophia Bethany Coban Problem Solving By Computer 22/23

Closing Notes Learning a new coding language often means a different way of thinking. Python is available in all platforms and running scripts is very common in/for all the devices, so it is very well integrated. We would be very impressed with you for being able to code in Python! You must remember that you would be more independent in finding solutions to your problems if you choose to code in Python. Don t be put off by the lack of a fancy gui and remember, practice makes perfect. Sophia Bethany Coban Problem Solving By Computer 22/23

Closing Notes Learning a new coding language often means a different way of thinking. Python is available in all platforms and running scripts is very common in/for all the devices, so it is very well integrated. We would be very impressed with you for being able to code in Python! You must remember that you would be more independent in finding solutions to your problems if you choose to code in Python. Don t be put off by the lack of a fancy gui and remember, practice makes perfect. Sophia Bethany Coban Problem Solving By Computer 22/23

Closing Notes Learning a new coding language often means a different way of thinking. Python is available in all platforms and running scripts is very common in/for all the devices, so it is very well integrated. We would be very impressed with you for being able to code in Python! You must remember that you would be more independent in finding solutions to your problems if you choose to code in Python. Don t be put off by the lack of a fancy gui and remember, practice makes perfect. Sophia Bethany Coban Problem Solving By Computer 22/23

Closing Notes Learning a new coding language often means a different way of thinking. Python is available in all platforms and running scripts is very common in/for all the devices, so it is very well integrated. We would be very impressed with you for being able to code in Python! You must remember that you would be more independent in finding solutions to your problems if you choose to code in Python. Don t be put off by the lack of a fancy gui and remember, practice makes perfect. Sophia Bethany Coban Problem Solving By Computer 22/23

Useful Links These slides can be found on www.maths.manchester.ac.uk/ scoban/python lecture psbc.pdf Also check out: Teach Yourself Python: http://www.codecademy.com/tracks/python Python Standard Library (choose your version on top): http://docs.python.org/2/library/ Differences between the versions: https://wiki.python.org/moin/python2orpython3 A huge collection of Python videos: http://pyvideo.org/ Educational/interesting videos about IPython: http://ipython.org/videos.html Sophia Bethany Coban Problem Solving By Computer 23/23