170 likes | 299 Vues
This overview provides a comprehensive introduction to Python programming language, created by Guido van Rossum and inspired by Monty Python. It covers essential concepts such as naming rules, data types, expressions, and assignments while explaining control structures like if/else and loops. Additionally, it touches on object-oriented programming and features that make Python unique, including its easy readability and garbage collection. Suitable for beginners to grasp Python's fundamental syntax and functionality.
E N D
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
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 • 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()
Python’s OOP cont… Python also has garbage collection!
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