Learning Python 5th Edition

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

The Web Warrior Guide to Web Design Technologies
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Python 101 Dr. Bernard Chen University of Central Arkansas IT Academic.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Input, Output, and Processing
Computer Science 101 Introduction to Programming.
Chapter Function Basics CSC1310 Fall Function function (subroutine, procedure)a set of statements different inputs (parameters) outputs In.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
Python Functions.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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.
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 Let’s get started!.
Function Basics. Function In this chapter, we will move on to explore a set of additional statements that create functions of our own function (subroutine,
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Introduction to python programming
Web Database Programming Using PHP
Python Programming Unit -1.
CST 1101 Problem Solving Using Computers
Introduction to GIS PythonScript CGIS-NURIntroduction to ArcGIS II.
Topics Designing a Program Input, Processing, and Output
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)
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Python Let’s get started!.
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
Web Database Programming Using PHP
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Variables, Expressions, and IO
JavaScript Syntax and Semantics
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
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Intro to PHP & Variables
Introduction to Python
Python Primer 2: Functions and Control Flow
WEB PROGRAMMING JavaScript.
Introduction to Python
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
CS190/295 Programming in Python for Life Sciences: Lecture 6
Topics Introduction Hardware and Software How Computers Store Data
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
CMSC 202 Java Primer 2.
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Python Primer 1: Types and Operators
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Intro to PHP.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
12th Computer Science – Unit 5
Programming Languages and Paradigms
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Learning Python 5th Edition Python Tutorial Learning Python 5th Edition

Why Python Python is a general-purpose programming language that is often applied in scripting roles. It is commonly defined as an object- oriented scripting language Why we use python Software quality Developer productivity Program portability Support libraries Component integration Enjoyment

Who Uses Python Today? Google, YouTube ,Dropbox storage service, The Raspberry Pisingle-board computer, EVE Online, a massively multiplayer online game (MMOG) by CCP Games, The widespread Bit Torrent peer-to-peer file sharing system, Industrial Light & Magic, Pixar, and others use Python in the production of animated movies. ESRI uses as customization tool for its popular GIS mapping products. Google’s App Engine web development framework The Iron Port email server product Maya, a powerful integrated 3D modeling and animation system, The NSA uses Python for cryptography and intelligence analysis. iRobot uses Python to develop commercial and military robotic devices

What can I do with python Systems Programming GUIs Internet Scripting Component Integration Database Programming Rapid Prototyping Numeric and Scientific Programming And More: Gaming, Images, Data Mining, Robots, Excel...

How Python Runs Programs? Python Interpreter An interactive version of python that works in interpreted way Hello to interpreter Make a file with name script0.py Write this code and save it Run Program as

How you run programs Interactive way Entering multiline statements Starting the python Or use GUI based environment Entering multiline statements

First Script Make a file in text editor (i.e. notepad) with name script1.py Run it like below route the printed output of a Python script to a file to save it for later use

Module import and reloads every file of Python source code whose name ends in a .py extension is a module You can import the file within python environment as To use script again and again in running session Use reload method A module is mostly just a package of variable names (known as a Namespace) the names within that package are called attributes. An attribute is simply a variable name that is attached to a specific object (like a module)

Module Properties Make a variable in a file called myfile.py Make a file threenames.py title = "The Meaning of Life"

Modules and namespaces are the largest program structure in Python programs, and one of the first key concepts in the language Name Space Python programs are composed of multiple module files linked together by import statements, and each module file is a package of variables each module is a self-contained namespace there are more ways to run code stored in module files

Variable Name Rules Syntax: (underscore or letter) + (any number of letters, digits, or underscores) Case matters: SPAM is not the same as spam Reserved words are off-limits Naming conventions Names that begin with a single underscore (_X) are not imported by a from module import * statement Names that have two leading and trailing underscores (__X__) are system-defined names that have special meaning to the interpreter Names that begin with two underscores and do not end with two more (__X) are localized (“mangled”) to enclosing classes The name that is just a single underscore (_) retains the result of the last expression when you are working interactively

Types and Operations The Python Conceptual Hierarchy Programs are composed of modules. Modules contain statements. Statements contain expressions. Expressions create and process objects.

Classes

Python Expressions

Variables and Basic Expressions Variables are created when they are first assigned values. Variables are replaced with their values when used in expressions. Variables must be assigned before they can be used in expressions. Variables refer to objects and are never declared ahead of time. comment

Dynamic Typing Variables, Objects, and References

Reference Checking

String Python strings are categorized as immutable sequences

String Implicit concatenation: title = "Meaning " 'of' " Life“ Repetition: Triple Quotes Code Multiline Block Strings

String Indexing and Slicing will fetch every other item in X from offsets 1–9 Character code conversions

Changing Strings Strings are immutable Method Call Syntax Attribute fetches An expression of the form object.attribute means “fetch the value of attribute in object. Call expressions An expression of the form function(arguments) means “invoke the code of function, passing zero or more comma-separated argument objects to it, and return function’s result value Method call expression: object.method(arguments)

String class methods

String Methods: Examples

String Method Examples: Parsing Text

Other Common String Methods in Action

String Formatting Expressions Allows us to perform multiple type-specific substitutions on a string in a single step String formatting expressions: '...%s...' % (values) String formatting method calls: '...{ }...'.format(values) Dictionary-Based Formatting Expressions

String Formatting Method Calls

Lists and Dictionaries Ordered collections of arbitrary objects Accessed by offset Variable-length, heterogeneous, and arbitrarily nestable Of the category “mutable sequence” Arrays of object references

Lists

Dictionaries Accessed by key, not offset position Unordered collections of arbitrary objects Variable-length, heterogeneous, and arbitrarily nestable Of the category “mutable mapping” Tables of object references (hash tables)

Tuples, Files, and Everything Else Ordered collections of arbitrary objects Accessed by offset Of the category “immutable sequence” Fixed-length, heterogeneous, and arbitrarily nestable Arrays of object references

Tuples in Action Concatenation Repetition Indexing/Slicing

Files

Files in Action

Storing Python Objects in Files: Conversions

Statements and Syntax

Assignment Statements

Expression Statements

Decision Statements

Switch statement Block Delimiters: Indentation Rules Statement Delimiters: Lines and Continuations Statements may span multiple lines if you’re continuing an open syntactic pair Statements may span multiple lines if they end in a backslash

Loops

Handling Errors with try Statements

Functions and Generators def is executable code def creates an object and assigns it to a name lambda creates an object but returns it as a result return sends a result object back to the caller yield sends a result object back to the caller, but remembers where it left off global declares module-level variables that are to be assigned nonlocal declares enclosing function variables that are to be assigned Arguments are passed by assignment (object reference) Arguments are passed by position, unless you say otherwise Arguments, return values, and variables are not declared def Executes at Runtime

Functions: Examples Definition Arbitrary scope nesting Calls

Arguments Arguments are passed by automatically assigning objects to local variable names Assigning to argument names inside a function does not affect the caller Changing a mutable object argument in a function may impact the caller Immutable arguments are effectively passed “by value.” Mutable arguments are effectively passed “by pointer.”

Keyword and Default Examples

Arbitrary Arguments Examples The last two matching extensions, * and ** (for keyword arguments only) , are designed to support functions that take any number of arguments.