python kick start
DESCRIPTION
Kick start to the world of PythonTRANSCRIPT
![Page 1: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/1.jpg)
ByKarthik Prakash
![Page 2: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/2.jpg)
• Introduction to Python
• Interactive “Shell”
• Basic Types and Containers
• Control Structures
![Page 3: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/3.jpg)
“Remarkable power with very clear syntax”
Python is an Interpreted, Object Oriented Programming language.
…it’s named after a television series Monty Python’s Flying Circus
It was created by Guido Van Rossum in the year 1990…
![Page 4: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/4.jpg)
Features :-
• Free and Open Source… Maintained by the PSF (Python Software Foundation)
• Rapid Prototyping
• Compiled to interpreted byte code .. sometimes called as Scripting language ….i.e Compilation is implicit
• Indentation for block structure…“Life's better without braces(Bruce Eckel)”
• Extremely Portable (Windows,Linux,Unix,Mac… etc)
• Powerful Standard libraries
![Page 5: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/5.jpg)
Two variations: IDLE (GUI) and PYTHON (command line)
• Most Python implementations work on CLI (Command Line Interface)
• Great for learning the language by experimenting with the library
• Great for testing your own modules
• Benefits of IDLE
• Multi Windows Text Editor• Interactive Command Shell• Syntax Highlighting• Auto-Indentation• Auto Completion extended to Intellisence
![Page 6: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/6.jpg)
• None• Numbers and Floats• Complex Numbers …. (i + j)• Floating point• Boolean…. True or False• “Strings”• u“Unicode”• Tuples ()• Lists []• Dictonaries {}
• Built-in Function “type()”
![Page 7: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/7.jpg)
• If, else, elif….
• Try and except
• While Loop
• For Loop
![Page 8: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/8.jpg)
• List Comprehension
• Functions
• Doc Strings … Smart way of Documenting modules
• File Handling …… read , write , append to file
![Page 9: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/9.jpg)
Single
[ <item operation> for item in sequence <if condition>]
Nested
Special care has to be taken for the nested list comprehension:
….when nesting list comprehensions, read from right to left.
![Page 10: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/10.jpg)
Function Definition :-
def name (arg1, arg2…. , argn)
“““ Documentation ””” #optional statements
. . .
return expression
name(arg1,arg2) # Call to <name>
![Page 11: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/11.jpg)
File Modes
• Mode Meaning • 'r' open for reading (default)
• 'w' open for writing, truncating the file first
• 'a' open for writing, appending to the end of the file if it exists
• 'b' binary mode
![Page 12: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/12.jpg)
f = open(filename, [mode])
• read(), readline(), readlines()
• write(), writelines()
• seek(pos), tell()
• close()
![Page 13: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/13.jpg)
• Classes
o Class Definition
o Class Objects
o Class Data members
o Class Methods
o Class Inheritance
![Page 14: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/14.jpg)
class Stack:"A well-known data structure…"def __init__(self): # constructorself.items = []def push(self, x):self.items.append(x) #. Push into the Stack…the sky is the limitdef pop(self):x = self.items[-1] # Pop from the stackdel self.items[-1]return xdef empty(self):return len(self.items) == 0 # Boolean result
![Page 15: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/15.jpg)
object = Stack() #--- Object of the Class “Stack”
….. Constructor invoked during Object instantiation
object.push(arg1) #---- Call to Class Method “push”
print object.items #---- Access the Class Data Member
![Page 16: Python Kick Start](https://reader036.vdocuments.site/reader036/viewer/2022062709/558e674c1a28ab8c218b46e5/html5/thumbnails/16.jpg)
• class BaseClass:
baseDataVar = 10 def baseMethods(self) statements
class DerivedClass(BaseClass):
def Method() print self.baseDataVar self.baseMethods() #-- Call to base class method