1 / 17

Jason Clark

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

kaori
Télécharger la présentation

Jason Clark

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Jason Clark

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

  3. What is Python? • Created by Guido van Rossum • Named after Monty Python • Inspired by ABC programming language • Originally developed for the Ameba operating system

  4. Compiled or Interpreted? • Interpreted • (although some would disagree)

  5. 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

  6. 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

  7. Scope

  8. Data Types

  9. 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

  10. 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.

  11. Control Structures • If/Else syntax • if condition: • print(value) • elif: • print(other value) • else: • print(other value) • (The while loop has similar syntax)

  12. 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.

  13. Python’s OOP • Class Employee: • def __init__(self, name, salary): • self.name = name • self.salary= salary • Employee.empCount+= 1 • defdisplayEmployee(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()

  14. Python’s OOP cont… Python also has garbage collection!

  15. 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

  16. Evaluation • Easy to use • High readability • Low writability • Open source

  17. Questions?

More Related