Download A variable`s data type is inferred from the assignment statement

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
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
 Originally developed for the Ameba operating system
Compiled or Interpreted?
Interpreted
(although some would disagree)
Naming
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 continued…
A variable’s data type is inferred from the
assignment statement.
Item_Name = “foo”
# a string
Item_Qty = 10
# an integer
Item_Value = 1000.23
# a floating point
Scope
Built-in names
Global
Local
Data Types
Numeric types
• Integer
• Floating point
• Complex
Boolean
String
Container types
• Tuple (a,b,c)
• Dictionary {a:b, c:d, e:f}
• List [a,b,c]
None
Expressions and Assignments
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 cont...
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.
Control Structures
If/Else syntax
if condition:
print(value)
elif:
print(other value)
else:
print(other value)
(The while loop has similar syntax)
Control Structures cont…
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.
Python’s OOP
Class Employee:
def __init__(self, name, salary):
self.name = name
self.salary = salary
Employee.empCount += 1
def displayEmployee(self):
self.salary
print "Name : ", self.name,
", 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 cont…
Overriding
methods
Overloading
operators
Inheritance
Python
OOP
Overloading
methods
Other Issues
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
Evaluation
Easy to use
High readability
Low writability
Open source
Questions?