jason clark

17
Jason Clark

Upload: kaori

Post on 23-Feb-2016

36 views

Category:

Documents


0 download

DESCRIPTION

Jason Clark. Overview. Naming rules Scope Data types Expressions Assignments Control structures Object Orientation Other things that make Python cool. What is Python?. Created by Guido van Rossum Named after Monty Python Inspired by ABC programming language - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Jason Clark

Jason Clark

Page 2: Jason Clark

2

Naming rules Scope Data types Expressions Assignments Control structures Object Orientation Other things that make Python cool

Overview

Page 3: Jason Clark

3

Created by Guido van Rossum

Named after Monty Python

Inspired by ABC programming language

Originally developed for the Ameba operating system

What is Python?

Page 4: Jason Clark

4

Compiled or Interpreted?

Interpreted (although some would disagree)

Page 5: Jason Clark

5

Variables must begin with a letter or an underscore

Numbers can be used after the first letter

Variables are case sensitive

Reserved words can’t be used

Naming

Page 6: Jason Clark

6

A variable’s data type is inferred from the assignment statement.

Item_Name = “foo” # a stringItem_Qty = 10 # an integerItem_Value = 1000.23 # a floating point

Naming continued…

Page 7: Jason Clark

7

Built-in namesGlobal

Local

Scope

Page 8: Jason Clark

8

Numeric types• Integer• Floating point• Complex

BooleanStringContainer types• Tuple (a,b,c)• Dictionary {a:b, c:d, e:f}• List [a,b,c]

None

Data Types

Page 9: Jason Clark

9

Expression precedence is similar to other languages

Comparison operators are similar to other languages

Supports coercion

Assignment operators are similar to other languages

Expressions and Assignments

Page 10: Jason Clark

10

The ins and outs…

Print allows users to output the value of the requested string, integer, or other data type.

Input allows users to input numbers and Booleans, but raw_input has to be used to allow users to input strings.

Expressions and Assignments cont...

Page 11: Jason Clark

11

If/Else syntax

if condition:

print(value)

elif:

print(other value)

else:

print(other value)

(The while loop has similar syntax)

Control Structures

Page 12: Jason Clark

12

The for loop iterates through a sequence.

Example of a for loop using the built-in range()for i in range(10)):

statement(s)

The for loop will iterate through a numerical sequence starting with 0 and ending with 9 in the previous example.

Control Structures cont…

Page 13: Jason Clark

13

Class Employee:

def __init__(self, name, salary):

self.name = name

self.salary = salary

Employee.empCount += 1

 

def displayEmployee(self):

print "Name : ", self.name, ", Salary: ", self.salary

 Class instantiation uses function notation and the parameters of the __init__ method: X = Employee(“Jason”,50000)Attributes of the object can be accessed using the dot operator with the object:X.displayEmployee()

Python’s OOP

Page 14: Jason Clark

14

Python

OOP

Overloading

operators

Overriding

methodsInheritan

ce

Overloading

methods

Python’s OOP cont…

Python also has garbage collection!

Page 15: Jason Clark

15

Forces indentation to distinguish blocks

# is used for single line comment. “”” is used for multiline comment

Concurrency is possible but very limited

Exception handling uses try/except instead of try/catch

Other Issues

Page 16: Jason Clark

16

Easy to use

High readability

Low writability

Open source

Evaluation

Page 17: Jason Clark

17

Questions?