NWEN241 – Systems Programming

Slides:



Advertisements
Similar presentations
I210 review Fall 2011, IUB. Python is High-level programming –High-level versus machine language Interpreted Language –Interpreted versus compiled 2.
Advertisements

Introduction to Python
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed.
CSC 9010: Natural Language Processing
Recitation 1 Programming for Engineers in Python.
INLS 560 – V ARIABLES, E XPRESSIONS, AND S TATEMENTS Instructor: Jason Carter.
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.
Intro to Python Programming (Introduction) Pamela A. Moore Zenia C. Bahorski Eastern Michigan University March 7, 2012 A language to swear by, not at.
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Munster Programming Training
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Python From the book “Think Python”
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Intro to Python Programming (Part 1) Pamela Moore Zenia Bahorski Eastern Michigan University March 16, 2011 A language to swear by, not at.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
An Introduction. What is Python? Interpreted language Created by Guido Van Rossum – early 90s Named after Monty Python
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.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Python Let’s get started!.
Variables, Types, Expressions Intro2CS – week 1b 1.
I NTRODUCTION TO PYTHON - GETTING STARTED ( CONT )
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
PYTHON PROGRAMMING. WHAT IS PYTHON?  Python is a high-level language.  Interpreted  Object oriented (use of classes and objects)  Standard library.
CMSC201 Computer Science I for Majors Lecture 03 – Variables
Fundamentals of Programming I Overview of Programming
Development Environment
CMSC201 Computer Science I for Majors Lecture 02 – Intro to Python
CS1022 Computer Programming & Principles
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Python Let’s get started!.
Introduction to Python
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
Presented By S.Yamuna AP/IT
Data types and variables
Variables, Expressions, and IO
Statement atoms The 'atomic' components of a statement are: delimiters (indents, semicolons, etc.); keywords (built into the language); identifiers (names.
Programming Language Concepts (CIS 635)
Engineering Innovation Center
Introduction to Python
String operations; More on function definitions; Conditional execution
Introduction to Python
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
Lecture 2 Python Programming & Data Types
PHP.
Units with – James tedder
Lecture 2 Python Programming & Data Types
Python Primer 1: Types and Operators
15-110: Principles of Computing
CISC101 Reminders All assignments are now posted.
12th Computer Science – Unit 5
PHP an introduction.
General Computer Science for Engineers CISC 106 Lecture 03
An Overview of C.
Dasar-Dasar Pemrograman 2: Java Basics
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
Python Reserved Words Poster
Learning Python 5th Edition
Introduction to Python
Introduction to Python
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

NWEN241 – Systems Programming Python!

NWEN241 and Python Bryan Ng Introduction to Python (3.6, not 2.7) bryan.ng@ecs.vuw.ac.nz AM404, appointments are essential. Introduction to Python (3.6, not 2.7) Lectures will be a combination of slides + notebooks (ipython) once we get through the easy stuff No tutorial this week Assignment + lab project will be out this week.

Resources Book: Think Python: How to think like a Computer Scientist Allen Downey, Green Tea Press Get the Python 3.x version at http://interactivepython.org/runestone/static/thinkcspy/toc.html Websites: How to Think Like a Computer Scientist Learning with Python: Interactive Edition 2.0 (Using Python 3.x) Brad Miller and David Ranum, Luther College http://interactivepython.org/courselib/static/thinkcspy/index.html UC Berkley Fall 2013 Bootcamp: http://www.pythonbootcamp.info/ PEP8: https://www.python.org/dev/peps/pep-0008/

Using Python at home Follow those instructions. Install it: https://www.python.org/downloads/windows/ Get 3.5.1 Follow those instructions. There will comments about adding it to your path Python comes with its own little shell you can use interactively Pick a nice IDE. PyCharm Eclipse (plugin) Sublime Text

Today Python overview How do you use it Debugging Basics!

Why these languages?

Python is: An *interpreted* language Object oriented High level (like C++/Java) – has many data types and structures Dynamically typed – set variables on the fly Designed for rapid application development Great as a scripting language – easy and fast Simple/easy to read and learn– no brackets/semicolons etc. Leverages modules and packages – code reuse Both interactive AND scriptable

The Python programming language Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed. http://www.python.org/doc/essays/blurb/

Development History

Development History Open-sourced development from the start (BSD-compatible licensed now) http://www.opensource.org/licenses/bsd-license.php Relies on large community input (bugs, patches) and 3rd party add-on software. Version 2.0 (2000), 2.6 (2008), 2.7 (2010). Version 3.X (2008) is not backward compatible with 1.X & 2.X. But 2.7 code is “easily” migrated to 3.X We will use this one (mostly). BSD licence imposes minimal restrictions on software you develop that uses Python. Also called “copycentre” unlike “copyright”, you can make as many copies as you want.

Who uses Python?

This is python 2.7 – note no brackets around the print statement.

Using Python: Interpreter mode Python 3.5.1 (default, Dec 20 2015, 10:41:17) [GCC 5.3.0] on linux Type "help", "copyright", "credits" or "license" for more >>> 2 + 3 5 >>> print(‘hello’) hello We use 3.5 now

Using Python: Script mode Create a file called firstprogram.py containing: #!/usr/bin/env python3 print("My first program adds two numbers, 2 and 3:") print(2 + 3) $ python3 firstprogram.py My first program adds two numbers, 2 and 3: 5

Firstly…

What is debugging? Syntax errors Semantic errors Runtime errors The “code” can’t be read by the interpreter Semantic errors The *valid* code doesn’t do what you want Runtime errors Issues during execution, e.g. index out of bounds Experimental debugging

Some bugs are hard! Of all my programming bugs, 80 percent are syntax errors. Of the remaining 20 percent, 80 percent are trivial logical errors. Of the remaining 4 percent, 80 percent are pointer errors. And the remaining 0.8 percent are hard. Marc Donner IBM T. 1. Watson Research Center

Designing for Test/Debug Think about how you are going to test/debug it lack of thought always translates into bugs Write test cases when you write your code Design for testing/debugging from the start Test early, test often Test at abstraction boundaries

Python basics: Values and Types Some values 1, 2.0, 'Hello, World!‘,True,None What type are these? In Python, we have a type operator type ('Hello, World!') <class 'str'> type (17) <class 'int'> Int, float, string, Boolean, NoneType

Python basics: Variables >>> message = 'And now for something completely different' >>> n = 17 >>> pi = 3.1415926535897931 >>> print (pi) 3.141592653589793 >>> type (pi) <class 'float'>

Python basics: Variable names Variable names can be arbitrarily long. They can contain both letters and digits, but they have to begin with a letter or an underscore It is a good idea to begin variable names with a lowercase letter (you’ll see why later). The underscore character (_) can appear in a name. A hyphen (-) cannot be in the name. Variable names cannot be key words (for, while, etc.)

Python basics: Keywords Python has thirty-something keywords and del from not while as elif global or with assert else if pass yield break except import print True class exec in raise False continue finally is return None def for lambda try nonlocal

Python basics: Variable names Legal or not legal? recvbuf 2rows totalNumber1 total_number2 total-number3 BigCounter lambda Yes No – no number to start with No – no hyphens No – no key words

Variables and maths variables are assigned on the fly unlike Java where must declare first type can be changed explicitly using type conversion function or leave it up to the interpreter multiplication, division, exponents as you expect logical bitwise operators and comparison operators

More on variables and types booleans are another type True, False and None type(obj) returns the type of the object isinstance(obj, type) allows you to check if obj is of type type

Strings Strings are a sequence of characters they can be indexed and sliced up as if they were an array you can glue strings together with + signs use ' or “ to delimit strings Strings are immutable (just like Java) - But you can change what the variable points to freely. Strings can be formatted and compared For example, is x a substring of y … 'x'in 'y'