Download presentation
Presentation is loading. Please wait.
1
Introduction to Python
2
Outline Python IS ……. History Installation Data Structures Flow of Control Functions Modules References
3
Python IS ….. Interpreted Like pseudo code, hence development-friendly Intuitive, easy to learn, understandable White-space sensitive; acts as delimiter Portable Extensive standard libraries Compatible with other languages It is OPEN source
4
History Invented in 1990 by Guido Van Rossum The name ‘Python’ stems from "Monty Python's Flying Circus“ Currently, he works for Google (since 2005). He wrote a web based code review tool for Google in Python.
5
Installation Available for FREE online IDLE is a known editor $cmd> python // opens the console >> print “hello” hello >> import “filename” ….
6
Data Structures Variables - need not be declared String - comes with usual string manipulations “hello” + “123” – gives “hello123” // Concat “Hello”*3 – gives “HelloHelloHello” // Repetition len(“array_name”) – gives 10 Lists list = [‘a’, ’b’, ’c’] Dynamic array Items can be of any type Indexed basedprint list[0] // prints ‘a’ Operations such as append(), insert(), pop(), reverse(), sort()
7
Dictionary Map of keys and values E.g. dictionary = {“key1:value1”, “key2:value2”, …..} Operations such as insert, delete, has_key(), keys(), values(), …. Example >> Polygons = {“triangle:3”, “rectangle:4”, “pentagon:5”} >> print Polygons[“triangle”] 3
8
References Address to the object referred Pointer_a = Pointer_b // doesn’t copy value Both now point to same object >> Pointer_a = [1,2] >> Pointer_b = Pointer_a >> Pointer_a.append(3) >> print b [1,2,3]
9
Tuples Consists of values separated by commas E.g. >> tuple = “12”, “abc”, 890 >> tuple[0] 12 Nesting allowed T = ((“1”, “abc”, 1234), (“2”, “pqr”, 5678)) Acts like a DB Tuples are immutable x,y,z = T // unpacking Special case for tuple with 0 or 1 items >> empty = ()// 0 items >> single = (‘123’,)// trailing comma
10
Flow of Control (no braces) If (condition): statement 1// Mark the indentation statement 2// Grouping else: statement1 while(condition): statement for var in seq: statement
11
break Continue Functions def name(arg1, arg2,….): statement… return // optional Example: def sum(num1, num2): return (num1 + num2)
12
Modules/Scripts: File containing statements and functions Comes with “.py” suffix Invoked by “import filename” Object-oriented
13
References: Python Homepage http://www.python.org Python Tutorial http://www.python.org/tut Python Documentation http://www.python.org/doc
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.