1 Python CIS*2450 Advanced Programming Concepts Material for this lecture was developed by Dr. D. Calvert.

Slides:



Advertisements
Similar presentations
Python Syntax. Basic Python syntax Lists Dictionaries Looping Conditional statements.
Advertisements

MC697 Object-Oriented Programming Using Java. In this class, we will cover: How the class will be structured Difference between object-oriented programming.
DICTIONARIES. The Compound Sequence Data Types All of the compound data types we have studies in detail so far – strings – lists – Tuples They are sequence.
What is a scripting language? What is Python?
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Introduction to Python Programming Languages Fall 2002 Adapted from Tutorial by Mark Hammond Skippi-Net, Melbourne, Australia
Python By Steve Wright. What is Python? Simple, powerful, GP scripting language Simple, powerful, GP scripting language Object oriented Object oriented.
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Python Brandon Jeffcoat Dashaun West “Why settle for snake oil when you can have the whole snake?” -- From Usenet posting by Mark Jackson, June 1998.
Introduction to Python. Outline Python IS ……. History Installation Data Structures Flow of Control Functions Modules References.
Python Crash Course by Monica Sweat. Python Perspective is strongly typed, interpreted language is used to define scripts (Don't even need to define a.
Guide To UNIX Using Linux Third Edition
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Introduction to Python (for C++ programmers). Background Information History – created in December 1989 by Guido van Rossum Interpreted Dynamically-typed.
Programming 101 with Python: an open-source, cross-platform, and fun language By J. Burton Browning, Ed.D. Copyright © J. Burton Browning All rights reserved.
V Avon High School Tech Club Agenda Old Business –Delete Files New Business –Week 18 Topics: Intro to HTML/CSS: Questions? Summer Work Letter.
Python Programming Fundamentals
January 24, 2006And Now For Something Completely Different 1 “And Now For Something Completely Different” A Quick Tutorial of the Python Programming Language.
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
1 Perl Perl basics Perl Elements Arrays and Hashes Control statements Operators OOP in Perl.
1. Python Overview Python is a high-level, interpreted, interactive and object oriented-scripting language. Python was designed to be highly readable which.
An Introduction to Unix Shell Scripting
Chapter 4 Numbers. Python Program Structure Python programs consist of: Modules Statements Expressions Objects.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Strings The Basics. Strings can refer to a string variable as one variable or as many different components (characters) string values are delimited by.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Python Lists and Such CS 4320, SPRING List Functions len(s) is the length of list s s + t is the concatenation of lists s and t s.append(x) adds.
For. for loop The for loop in Python is more like a foreach iterative-type loop in a shell scripting language than a traditional for conditional loop.
An Introduction to Python Blake Brogdon. What is Python?  Python is an interpreted, interactive, object-oriented programming language. (from python.org)
Built-in Data Structures in Python An Introduction.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
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.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
An Introduction. What is Python? Interpreted language Created by Guido Van Rossum – early 90s Named after Monty Python
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Python Basics Tom LeFebvre. Sept , 2002Python Basics2 Python Language Very High-Level Language Scripting Language (no compiling) Simple syntax Easy.
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.
Scripting with Ruby What is a scripting language? What is Ruby?
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
PHP vs. Python. Similarities are interpreted, high level languages with dynamic typing are Open Source are supported by large developer communities are.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Program Development Cycle 1.Edit program 2.Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied,
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
PYTHON PROGRAMMING. WHAT IS PYTHON?  Python is a high-level language.  Interpreted  Object oriented (use of classes and objects)  Standard library.
PHP using MySQL Database for Web Development (part II)
Fundamentals of Programming I Overview of Programming
Python Variable Types.
Ruby: An Introduction Created by Yukihiro Matsumoto in 1993 (named after his birthstone) Pure OO language (even the number 1 is an instance of a class)
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
Intro To Pete Alonzi University of Virginia Library
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during.
Functions CIS 40 – Introduction to Programming in Python
PHP Introduction.
Perl for Bioinformatics
Introduction to Python
Introduction to Python
An overview of Java, Data types and variables
PHP.
Python Primer 1: Types and Operators
(more) Python.
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

1 Python CIS*2450 Advanced Programming Concepts Material for this lecture was developed by Dr. D. Calvert.

2 What is Python? Python is an object-oriented scripting language developed by Guido van Rossum. It supports polymorphism, operator overloading and multiple inheritance. It is easy to bind to other languages: –Extend call components written in C or C++ –Embed call Python from C or C++ –Jython is an implementation written in Java and can be used to link with Java

3 What is Python? It is portable and available on most platforms including Unix/Linux, Windows, Mac OS, Be-OS, VMS. There exist many libraries for Python which support complex programming tasks including networking, GUIs, object serialization, and complex math. It is interpreted which allows for a rapid development cycle.

4 Basic Syntax There is no end-of-line character other than the newline (carriage return). Blocks of code are identified using indentation and not a begin-end or brace {} pair. –Consistent indentation is important or the interpreter will not work properly. –Care must be taken when mixing TABs and spaces. Comments begin with the # sign (pound or hash). –Everything to the end-of-line is ignored.

5 Basic Syntax The script should contain a very specific first line which tells the operating system what program will interpret the script. #!/usr/bin/python –The #! characters tell the OS to run the program which follows. –Other scripting languages would use other interpreters. #!/usr/bin/perl #!/bin/bash The script must be executable chmod u+x

6 Variables Python has built-in support for numbers and strings as well as several more complex data structures. Normal integer and floating-point numbers are supported. –3, 3.0, 3.14e-10 Infinitely long integers – L

7 Variables Octal and Hexadecimal numbers –0177, 0x9ff Complex numbers –3 + 4j

8 Variables Strings using either single or double quotes s1 = “fred” s2 = ‘fred’ s3 = “fred’s” s4 = s1 + s2 # concatenation print s4 # output fredfred print s4[2] # output e print s4[2:4] # output ed print len(s4) # output 8 which is the string length

9 Complex Structures Python supports several other complex data structures: –Lists –Dictionaries –Tuples

10 Lists Lists are ordered collections of other objects. They can contain numbers, strings, or other lists. They are accessed using an index. They have a variable length - can grow and shrink in place.

11 List Example #!/usr/bin/python L1 = ["abc", 123, "fred"] print L1[1] # outputs 123 print L1[0:2] # outputs ['abc', 123] print len(L1) # outputs 3 for x in L1: print x # outputs abc, 123, fred each # on a separate line L1.append("betty") # adds betty to the list print L1 # outputs ['abc', 123, 'fred', 'betty']

12 Dictionaries Dictionaries are unordered collections of objects. They are identified using a key instead of an index. They are similar to arrays - often called associative (or associate) arrays.

13 Dictionaries Example #!/usr/bin/python table = {"nut" : 1.0, "bolt": 2.0, "widget": 0.5, "gadget": 1.0} print table["nut"] # references element through key # output is 1.0 print len(table) # 4 print table.has_key("widget") # outputs 1 (true) print table.keys() # ['gadget', 'bolt', 'nut', 'widget']

14 Tuples Tuples are exactly like lists but they are immutable (value cannot be changed in place). To change the value you must create a new tuple. They are useful if you want to guarantee that some data will not be changed accidentally.

15 Some Coding Principles Each file foo.py is considered to contain a module foo. Importing a module executes its top-level code (like calling it) and makes its functions known A module’s name is available in the built-in __name__ variable: –The initial file being executed is named __main__. –An imported module takes the module’s name.

16 Module Example foo.py #!/usr/bin/python print “Hi, my name is ”,__name__ python foo.py Hi, my name is __main__ python >>>import foo Hi, my name is __foo__

17 Control Structures The if, else, and for statements end with a colon and the code under them is indented to show which lines constitute the control block. string1 = “barney” for c in string1: print c, # the comma means do not move print # to a new line

18 Control Structures if string1 == “barney” : print “rubble” else : print “flintstone”

19 The range() function for i in range(5) : print i The range() function returns a list of incrementing integers which count to one less than the parameter value. –range(3) returns [0,1,2]