Indentations makes the scope/block Function definition def print_message (): print “hello” Function usages print_message () hubo.move ()// hubo is a class.

Slides:



Advertisements
Similar presentations
Python Mini-Course University of Oklahoma Department of Psychology Day 4 – Lesson 15 Tuples 5/02/09 Python Mini-Course: Day 4 – Lesson 15 1.
Advertisements

I210 review Fall 2011, IUB. Python is High-level programming –High-level versus machine language Interpreted Language –Interpreted versus compiled 2.
Week 5 while loops; logic; random numbers; tuples Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except.
Jay Summet CS 1 with Robots IPRE Python Review 1.
Structured programming
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.
Lilian Blot CORE ELEMENTS COLLECTIONS & REPETITION Lecture 4 Autumn 2014 TPOP 1.
1 CSC 221: Introduction to Programming Fall 2012 course overview  What did you set out to learn?  What did you actually learn?  Where do you go from.
January 24, 2006And Now For Something Completely Different 1 “And Now For Something Completely Different” A Quick Tutorial of the Python Programming Language.
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
H3D API Training  Part 3.1: Python – Quick overview.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Functions.
Python – Part 3 Functions 1. Function Calls Function – A named sequence of statements that performs a computation – Name – Sequence of statements “call”
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
 Expression Tree and Objects 1. Elements of Python  Literals, Strings, Tuples, Lists, …  The order of file reading  The order of execution 2.
Functions. Built-in functions You’ve used several functions already >>> len("ATGGTCA")‏ 7 >>> abs(-6)‏ 6 >>> float("3.1415")‏ >>>
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
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
Introduction to Computing Using Python for loop / def- ining a new function  Execution control structures ( if, for, function call)  def -ining a new.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Exam 1 Review Instructor – Gokcen Cilingir Cpt S 111, Sections 6-7 (Sept 19, 2011) Washington State University.
An Introduction. What is Python? Interpreted language Created by Guido Van Rossum – early 90s Named after Monty Python
Python – Part 3 Functions 1. Getting help Start the Python interpreter and type help() to start the online help utility. Or you can type help(print) to.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
INLS 560 – F UNCTIONS Instructor: Jason Carter.
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
A Tutorial on the Python Programming Language. Overview Running Python and Output Data Types Input and File I/O Control Flow Functions.
Scope, Aliasing, Tuples & Mutability Intro2CS – week 4a 1.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Python Basics  Functions  Loops  Recursion. Built-in functions >>> type (32) >>> int(‘32’) 32  From math >>>import math >>> degrees = 45 >>> radians.
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
Xi Wang Yang Zhang. 1. Easy to learn 2. Clean and readable codes 3. A lot of useful packages, especially for web scraping and text mining 4. Growing popularity.
Functions Chapter 4 Python for Informatics: Exploring Information Slightly modified by Recep Kaya Göktaş on March 2015.
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
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.
Find LCM Least Common Multiple of 3 and 5: List the Multiples of each number, The multiples of 3 are 3, 6, 9, 12, 15, 18,... etc The multiples of 5 are.
Python Basics.
Scientific Programming in Python -- Cheat Sheet
Python Review 1.
Topics Introduction to Functions Defining and Calling a Void Function
Introduction to Python
Computer Programming Fundamentals
CS 100: Roadmap to Computing
Python: Control Structures
CS-104 Final Exam Review Victor Norman.
Lecture 24: print revisited, tuples cont.
Basic operators - strings
CSC 108H: Introduction to Computer Programming
CISC101 Reminders Assn 3 due tomorrow, 7pm.
CSC1018F: Intermediate Python
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
G. Pullaiah College of Engineering and Technology
CISC101 Reminders Assignment 2 due today.
Nate Brunelle Today: Conditional Decision Statements
COMPUTER PROGRAMMING SKILLS
Programming Languages and Paradigms
CISC101 Reminders Assignment 3 due today.
def-ining a function A function as an execution control structure
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
Functions John R. Woodward.
Introduction to Computer Science
Presentation transcript:

Indentations makes the scope/block Function definition def print_message (): print “hello” Function usages print_message () hubo.move ()// hubo is a class Loops for i in range (4): print “Hello” print “Hehe!” Boolean: True/False, Logical op.: not, and, or Conditionals if a: do this else: do that Many choices if a: do this elif b: do that else: do those Module imports from cs1robts import * Every Python data is an object with its type: int, float, str, complex, bool, tuple, class, etc. Empty variable: None (NoneType) Boolean expression: ==, !=, <, etc. Unpack tuples: x, y, x = position while a: hubo.move() >>> type (3) >>> type (Robot()) >>> type ((1, 2))

Functions take arguments and return a result: import math def to_radians(deg): #deg is a parameter and a local variable return (deg/180.0*math.pi >>> a = to_radians (90) # 90 is an argument Functions w/o the return keyword return None; it can return tuples for multiple data raw_input ()  takes keyboard input Local vs. global variables Global variables are defined outside functions Variables defined within functions are local “global” keyword enables us to update global variables within functions Importing modules import math print math.pi from math import * print pi from math import pi print pi Mutable vs. immutable objects string and tuples are immutable Functions are also objects print f  # f is a function Lists are mutable Gold = [2, 4] >>> Gold [-1] 4 >>> len(Gold) 2 >> range (2) [0, 1] # range func. returns a list Built-in functions on lists len, sum, max, min, sort, reverse, append, etc. Slicing: mylist [i:j] # return i, i+1,.., j-1 Lists, tuples, strings are a kind of sequence. Conversion is possible >>> lists (t) >>> tuple (Gold) >>> t = Gold >>> t is Gold True

Arguments are mapped to parameters one-by- one, left-to-right Default parameters: def creat_f (radius = 30, color = “yellow”): … >>> create (2), but not create (“silver”) Named parameters: create (color = “silver”) Formatting operator: % E.g., %.2f (2 digits after the period), %3d, %-3d, %g, %s String methods Islapha(), rstrip(), relpace (s1, s2), find (str), etc. File access f = open (..), f.readline (), f.write (), f.close () Loop control: break, continue Object creation: class Card(object): """A Blackjack card.""" def value(self): if type(self.face) == int: … # constructor def __init__(self, face, suit): … # string coversion def __str__(self): …. #equality def __eq__(self, rhs):.. card = Card(8, “Clubs”)

Interpreter vs. compiler Compiler is faster, but interpreter is more convenient for testing and debugging Designing smarter algorithms can be better than using faster computer or using compiler instead of interpreter Recursion: calls itself There should be a termination condition You can use programs to answer to questions!