Intro to Python Paul Martin. History Designed by Guido van Rossum Goal: “Combine remarkable power with very clear syntax” Very popular in science labs.

Slides:



Advertisements
Similar presentations
What type of data can a variable hold?
Advertisements

Intro to Scala Lists. Scala Lists are always immutable. This means that a list in Scala, once created, will remain the same.
What is a scripting language? What is Python?
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Introduction to Python
Chapter 2 Writing Simple Programs
Intro to Programming Part of Chapter 5. Algorithms An algorithm is an ordered set of executable steps that defines a terminating process. An algorithm.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.3 The Class String.
Introduction to Python. What is Python? Interpreted object oriented high level programming language – No compiling or linking neccesary Extensible: add.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Python Control of Flow.
Created By Mayson Al-Duwais1. Using Exit to Terminate Repetition Statements To terminate different types of repetition statements you can use a special.
Python.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Programming for Linguists An Introduction to Python 24/11/2011.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Munster Programming Training
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
Input, Output, and Processing
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
If statements while loop for loop
Intro to Python Adriane Huber Debbie Bartlett Python Lab #1Python Lab #1 1.
Q and A for Sections 2.9, 4.1 Victor Norman CS106 Fall 2015.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Python The tutorial
With Python.  One of the most useful abilities of programming is the ability to manipulate files.  Python’s operations for file management are relatively.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 11 Using strings and sequences 5/02/09 Python Mini-Course: Day 3 – Lesson.
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
Variables, Types, Expressions Intro2CS – week 1b 1.
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
PYTHON VARIABLES : CHAPTER 2 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
Python 1 SIGCS 1 Intro to Python March 7, 2012 Presented by Pamela A Moore & Zenia C Bahorski 1.
Loops (While and For) CSE 1310 – Introduction to Computers and Programming 1.
Introduction to Python Sajal Desai. What is Python? Versitile, simple, high level language No linking and compilation “By the way, the language is named.
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
PYTHON PROGRAMMING. WHAT IS PYTHON?  Python is a high-level language.  Interpreted  Object oriented (use of classes and objects)  Standard library.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
Mr. Crone.  Use print() to print to the terminal window  print() is equivalent to println() in Java Example) print(“Hello1”) print(“Hello2”) # Prints:
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
ENGINEERING 1D04 Tutorial 1. WELCOME! What we’re doing today Who am I How to do well What are computer programs Software Development Cycle Pseudo Code.
Chapter 2 Writing Simple Programs
G. Pullaiah College of Engineering and Technology
C++ First Steps.
Topics Designing a Program Input, Processing, and Output
Topic: Iterative Statements – Part 1 -> for loop
Pamela Moore & Zenia Bahorski
Intro To Pete Alonzi University of Virginia Library
CS-104 Final Exam Review Victor Norman.
Basic operators - strings
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during.
Arithmetic operations, decisions and looping
Introduction to Python
Introduction To Python
An Introduction to Python
CS190/295 Programming in Python for Life Sciences: Lecture 6
CMSC 202 Java Primer 2.
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
Introduction to Programming with Python
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
LOOP Basics.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Intro to Python Paul Martin

History Designed by Guido van Rossum Goal: “Combine remarkable power with very clear syntax” Very popular in science labs – "scientists often need to improvise when trying to interpret results, so they are drawn to dynamic languages which allow them to work very quickly and see results almost immediately.“ Guido van Rossum

Compiling and Comments Start Python by typing Python – or Python myFileName # is symbol to comment line – Can be placed on it’s own line or after code

Variable Assignment ‘=‘ is the assignment operator Can apply = operator to many vars at one time – ex. x = y = z = 0

Variable Assignment Cont. No identifier required – height = 5 To declare a floating point variable – width = 3.3 Can declare a variable with an equation – ex. area = width*height #width,height def above

Complex Numbers CmpNum = real + imagj – ex. Cmpnum = j Access real numbers via Cmpnum.real Access imaginary numbers via Cmpnum.imag Magnitude can be found by abs(Cmpnum)

Strings Can be declare with single or double quote – “Hello World” or ‘Hello World’ Can use quote marker inside string when with the escape character ‘\’ – ex. ‘This isn\’t the end’ Can also use the other type of quote marker – ex. “This isn’t the end”

String Concatenation and Length Word = ‘str’ + ‘ing’ Word = ‘str’ ‘ing’ Length = len(Word) – For the above word, length will be equal to 6

String Indexing Start from index 0 Word = ‘HelpA’ – Word[4] = ‘A’ –letter at index 4 – Word[0:2] = ‘He’ –letters index 0 <= x < 2 – Word[0:100] = ‘HelpA’ – Word[:2] = ‘He’ –letters index x < 2 – Word[2:] = ‘lpA’ –letters index x > 2 – Word[3:1] = ‘’ – Accessing in reverse order via the negative sign Word[-2] = ‘p’

Lists List = [‘a’,’b’,2,3] Index Starts from 0 Accessing Elements – List[1] = ‘b’ – List[2:4] = [2, 3] Lists can be nested – List2 = [1,List,2] List length accessed from len(List)

Mutating Lists Lists can be changed – List[3] = List[3] + 40 Elements can be removed/inserted – Insert List[1:1] = [‘aa’,’ab’] – Remove List[0:2] = []

If Statements If x == 0: Do Something elif x == 1: Do Something Else else: Do Anything Else To end statement press enter on an empty line

While and Pass Statements while statement same function as C pass statement does nothing – Used when program requires no action while x == 5: pass #this program will continue as long as x = 5 and #user does not interrupt

Range Statements Useful for performing a loop x amount of times range(10) – creates list [0,1,2,3,4,5,6,7,8,9] range(5,10) – creates list [5,6,7,8,9] range(0,20,5) – Creates list [0,5,10,15]

For Statements Iterates over items of a sequence for x in a: print x break and continue statements same as C – break – exit nearest loop – continue – continue to next iteration of loop

For Else Statements Executed if loop not terminated by break for n in range(2, 10): if n == 11 print ’11 found’ break else: print ‘no 11 found’

Function Definitions def fun(m): if m == 1: print ‘m = 1’ fun(1) – prints ‘m = 1’ fun(2) – prints nothing

References _2010/cs_265_links.htm world/7-programming-languages-the-rise-620