jason clark
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 PresentationTRANSCRIPT
Jason Clark
2
Naming rules Scope Data types Expressions Assignments Control structures Object Orientation Other things that make Python cool
Overview
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?
4
Compiled or Interpreted?
Interpreted (although some would disagree)
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
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…
7
Built-in namesGlobal
Local
Scope
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
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
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...
11
If/Else syntax
if condition:
print(value)
elif:
print(other value)
else:
print(other value)
(The while loop has similar syntax)
Control Structures
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…
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
14
Python
OOP
Overloading
operators
Overriding
methodsInheritan
ce
Overloading
methods
Python’s OOP cont…
Python also has garbage collection!
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
16
Easy to use
High readability
Low writability
Open source
Evaluation
17
Questions?