Python Basics Tom LeFebvre. Sept. 24-27, 2002Python Basics2 Python Language Very High-Level Language Scripting Language (no compiling) Simple syntax Easy.

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. Python is a high-level programming language Open source and community driven “Batteries Included” – a standard distribution includes.
Title An Introduction to Python. What is Python exactly? Python is a modern rapid development language. Code is very clean and easy to read. Emphasizes.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Introduction to Python. Outline Python IS ……. History Installation Data Structures Flow of Control Functions Modules References.
Chapter 2 Writing Simple Programs
Intro to Python Paul Martin. History Designed by Guido van Rossum Goal: “Combine remarkable power with very clear syntax” Very popular in science labs.
1 Outline 7.1 Introduction 7.2 Implementing a Time Abstract Data Type with a Class 7.3 Special Attributes 7.4Controlling Access to Attributes 7.4.1Get.
Introduction to Python (for C++ programmers). Background Information History – created in December 1989 by Guido van Rossum Interpreted Dynamically-typed.
Python Control of Flow.
Python quick start guide
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.
Dr. Ken Hoganson, © August 2014 Programming in R STAT8030 Programming in R COURSE NOTES 1: Hoganson Programming Languages.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Introduction to Python John Reiser May 5 th, 2010.
Builtins, namespaces, functions. There are objects that are predefined in Python Python built-ins When you use something without defining it, it means.
Python: An Introduction
1 Python CIS*2450 Advanced Programming Concepts Material for this lecture was developed by Dr. D. Calvert.
Python 2 SIGCS 1 Intro to Python March 7, 2012 Presented by Pamela A Moore & Zenia C Bahorski 1.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
If statements while loop for loop
Simple Functions and Names Sec 9-4 Web Design. Objectives The student will: Know how to create a simple function in Python. Know how to call a function.
Getting Started with Python: Constructs and Pitfalls Sean Deitz Advanced Programming Seminar September 13, 2013.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Python Functions.
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 7 Conditionals and Loops 4/18/09 Python Mini-Course: Day 2 - Lesson 7.
I Power Higher Computing Software Development Development Languages and Environments.
OCR GCSE Computing © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 1: Introduction.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
1 5.4 Modular Design Top-Down Design Structured Programming Advantages of Structured Programming.
Program Style Chapter 22 IB103 Week 12 (part 2). Modularity: the ability to reuse code Encapsulation: hide data access directly but may use methods (the.
Software Development. Software Development Loop Design  Programmers need a solid foundation before they start coding anything  Understand the task.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
Python Basics  Functions  Loops  Recursion. Built-in functions >>> type (32) >>> int(‘32’) 32  From math >>>import math >>> degrees = 45 >>> radians.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
The Python Language Petr Přikryl Part IIb Socrates IP, 15th June 2004 TU of Brno, FIT, Czech Republic.
Python Flow of Control CS 4320, SPRING Iteration The ‘for’ loop is good for stepping through lists The code below will print each element in the.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Programming In Python. Starter Using the internet… Find what a programming language is.
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.
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.
Python Joseph Eckstrom, Benjamin Moore, Willis Kornegay.
Intro to Programming STARS College of Communication and Information Florida State University Written by: Hannah Brock Alissa Ovalle Nicolaus Lopez Martin.
Indentations makes the scope/block Function definition def print_message (): print “hello” Function usages print_message () hubo.move ()// hubo is a class.
Python. Quick Points About Python Python is an interpreted language –Like Perl you don’t have to compile it –It has a command line interpreter if you.
Clojure Macros. Homoiconicity All versions of Lisp, including Clojure, are homoiconic This means that there is no difference between the form of the data.
Chapter 2 Writing Simple Programs
Scientific Programming in Python -- Cheat Sheet
Intro To Pete Alonzi University of Virginia Library
Topic: Functions – Part 2
Statement atoms The 'atomic' components of a statement are: delimiters (indents, semicolons, etc.); keywords (built into the language); identifiers (names.
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
CISC101 Reminders Assn 3 due Friday, this week. Quiz 3 next week.
CS190/295 Programming in Python for Life Sciences: Lecture 6
Loops CIS 40 – Introduction to Programming in Python
Python Jumpstart.
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
CISC101 Reminders All assignments are now posted.
Clojure Macros.
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
Selamat Datang di “Programming Essentials in Python”
Presentation transcript:

Python Basics Tom LeFebvre

Sept , 2002Python Basics2 Python Language Very High-Level Language Scripting Language (no compiling) Simple syntax Easy to Learn/Use Slow execution

Sept , 2002Python Basics3 Indentation Python uses indentation to identify blocks of code Might be difficult to get used to Code is more readable

Sept , 2002Python Basics4 Code Comments Code comments are identified with the “#” symbol Example # Print the value print “The value is:”, value

Sept , 2002Python Basics5 Statements The “if” statement has the syntax: if condition1 : doSometing elif condition2: doSomethingDifferent elif condition3: doAnotherThing else: doSomethingElse

Sept , 2002Python Basics6 Statements (cont.) The “for” loop has the syntax: The range statement is very useful for iterator in list: doSomethingWithTheIterator range(0,10) is the same as [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] for i in range(10): print i

Sept , 2002Python Basics7 The def Statement The “def” statement starts a method. def myMethod: print “myMethod executing.”

Sept , 2002Python Basics8 Data Structures - Lists List: a (mixed) collection of objects Lists are mutable Lists may be nested: [ [1, 2, 3], [ 6, 7 ]] myList = [“hello”, 2, 10.24] myList[2] = print myList [“hello”, 2, 20.48]

Sept , 2002Python Basics9 Data Structures - Tuples Tuple: an immutable (mixed) collection of objects cityInfo = (‘Boulder’, (40.0, )) cityName, location = cityInfo #copy out components print cityName Boulder print location (40.0, )

Sept , 2002Python Basics10 Data Structures - Dictionaries Dictionary: non-ordered collection referred to by a “key”. myDict = { ‘joe’ : (‘Joseph Smith’, ‘Private”, ), ‘sam’:(‘Samuel Jones’, ‘Sergeant”, ), ‘bob’:(‘Robert Doe’, ‘General’, ), } key : data

Sept , 2002Python Basics11 Other Peoples’ Code Much code has already been written that can greatly help you. Two types of “outside” code: – Modules – loose collection of methods – Classes – tightly-coupled, coherent collection of data and methods

Sept , 2002Python Basics12 Modules Modules are a collection of Python methods You can access modules by using “import” import math print math.pi OR from math import * print pi

Sept , 2002Python Basics13 Classes Python is an Object-Oriented language Class: a collection of data and methods – Data - things – Methods - actions class MyClass: def DoSomething(): def printSomething():

Sept , 2002Python Basics14 Inheritance Code can “inherit” from classes myTool inherits from class SmartScript myTool has access to the data and methods in SmartScript To access data or methods in any class use: myTool(SmartScript.SmartScript): self.

Sept , 2002Python Basics15 Where to use self. When calling method: When accessing data: When defining a new function: self.method() a = self.dataVariable a = self.dataVariable def myNewMethod(self, arg1, arg2):

Sept , 2002Python Basics16 Good Programming Practices Modularization – Break up code into smaller pieces each of which performs some small task avoids long methods improves readability easier to understand/maintain easier to find bugs

Sept , 2002Python Basics17 Good Programming Practices Documentation – Should be short – Include one sentence for each method – In-line documentation where necessary – Choose names well For methods – use verbs For data variables – use nouns

Sept , 2002Python Basics18 Troubleshooting Use print statements Add code incrementally & test