Your SlideShare is downloading. ×
Learn python
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Learn python

3,722
views

Published on

Learn python in linux and kick start your career

Learn python in linux and kick start your career

Published in: Technology

1 Comment
7 Likes
Statistics
Notes
  • super....!!!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
3,722
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
249
Comments
1
Likes
7
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • - needs Software Freedom Day@Alexandria University
  • Write most useful links for beginners starting
  • Write something more interactive
  • Transcript

    • 1. Programming at the speed of light Pythonism Kracekumar.R [email_address]
    • 2. Agenda
      • What is Python ???
      • 3. Why Python ???
      • 4. Syntax Walkthroughs
      • 5. Linux and Python
    • 6. What is Python ???
      • What is Python ???
      • 7. Why Python ???
      • 8. Syntax Walkthroughs
      • 9. Linux and Python
    • 10. History
      • Created by Guido von Rossum in 1990 (BDFL)
      • 11. named after Monty Python's Flying Circus
      • 12. http://www.python.org/~guido/
      • 13. Blog http://neopythonic.blogspot.com/
      • 14. Now works for Google
    • 15. What is Python ???
      • general-purpose high-level programming language, often used as a scripting language.
      • 16. interpreted, interactive, object-oriented.
      • 17. incorporates modules, exceptions, dynamic typing, very high level dynamic data types, and classes, automatic memory management.
      • 18. remarkable power with very clear syntax.
      • 19. has interfaces to many system calls and libraries, as well as to various window systems, and is extensible in C or C++.
    • 20. What is Python ???
      • supports multiple programming paradigms (primarily object oriented, imperative, and functional)
      • 21. portable: runs on many Unix variants, on the Mac, and on PCs under MS-DOS, Windows, Windows NT, OS/2, FreeBSD Solaris, OS/2, Amiga,AROS, AS/400, BeOS, OS/390, z/OS, Palm OS, QNX, VMS, Psion, Acorn RISC OS, VxWorks, PlayStation, Sharp Zaurus, Windows CE and even PocketPC !
    • 22. What is Python ???
      • Developed and supported by a large team of volunteers - Python Software Foundation
      • 23. Major implementations: CPython, Jython, Iron Python, PyPy
        • CPython - implemented in C, the primary implementation
        • 24. Jython - implemented for the JVM
        • 25. Pypy - implemented in Python
        • 26. IronPython - implemented in C#, allows python to use the .NET libraries
    • 27. Why Python ???
      • What is Python ???
      • 28. Why Python ???
      • 29. Syntax Walkthroughs
      • 30. Linux and Python
    • 31. Why Python ???
      • Readability, maintainability, very clear readable syntax
      • 32. Fast development and all just works the first time...
      • 33. very high level dynamic data types
      • 34. Dynamic typing and automatic memory management
      • 35. Free and open source
        • Implemented under an open source license. Freely usable and distributable, even for commercial use.
      • Simplicity , Great first language
      • 36. Availability (cross-platform)
      • 37. Interactivity (interpreted language)
    • 38. Why Python ???
      • GUI support – GUIs typically developed with Tk
      • 39. Strong introspection capabilities
      • 40. Intuitive object orientation
      • 41. Natural expression of procedural code
      • 42. Full modularity, supporting hierarchical packages
      • 43. Exception­based error handling
      • 44. The ability to be embedded within applications as a scripting interface
      • 45. Scalable – can play nicely with other languages
    • 46. Batteries Included
      • The Python standard library is very extensive
        • regular expressions, codecs
        • 47. date and time, collections, threads and mutexs
        • 48. OS and shell level functions (mv, rm, ls)
        • 49. Support for SQLite and Berkley databases
        • 50. zlib, gzip, bz2, tarfile, csv, xml, md5, sha
        • 51. logging, subprocess, email, json
        • 52. httplib, imaplib, nntplib, smtplib
        • 53. and much, much more ...
    • 54. Python Libraries
      • Biopython - Bioinformatics
      • 55. SciPy - Linear algebra, signal processing
      • 56. NumPy - Fast compact multidimensional arrays
      • 57. PyGame - Game Development
      • 58. Visual Python - real-time 3D output
      • 59. Django - High-level python Web framework
      • 60. and much more ...
    • 61. E.g. Projects with Python
      • Websites: Google, YouTube, Yahoo Groups & Maps, CIA.gov
        • Appengine: http://code.google.com/appengine/
        • 62. ” Google: Python has been an important part of Google since the beginning.”, Peter Norvig.
        • 63. Python application servers and Python scripting to create the web UI for BigTable (their database project)
      • Systems: NASA, LALN, CERN, Rackspace
        • Nasa Nebula http://nebula.nasa.gov/about
      • Games: Civilization 4, Quark (Quake Army Knife)
      • 64. Mobile phones: Nokia S60 (Symbian), PythonCE
      • 65. P2P: BitTorrent
    • 66. Cont . . .
      • Maya, a powerful integrated 3D modeling and animation system, provides a Python scripting API.
      • 67. EVE Online, a Massively Multi player Online Game (MMOG), makes extensive use of Python.
      • 68. iRobot uses Python to develop commercial robotic devices.
    • 69. What can you do with Python
      • Systems Programming
      • 70. GUI
      • 71. Internet Scripting
      • 72. Database Programming
      • 73. Numeric and Scientific Programming
      • 74. Natural language analysis
    • 75. What people say about Python ?
      • I can remember many Python idioms because
      they're simpler. That's one more reason I program faster [in Python]. I still have to look up how to open a file every time I do it in Java. In fact, most things in Java require me to look something up. --Bruce Eckel
    • 76. Cont . . .
      • Python ... is compact -- you can hold its entire
      feature set (and at least a concept index of its libraries) in your head. -- Eric S. Raymond
    • 77. Syntax Walkthroughs
      • What is Python ???
      • 78. Why Python ???
      • 79. Syntax Walkthroughs
      • 80. Linux and Python
    • 81. Talk is cheap. Show me the code. Linus Torvaldus
    • 82. Hello World
      • Python 2.6
      • Python 3.0
      print (“Hello World”) print “Hello World”
    • 83. Starting python
      • Open terminal and Enter python and hit enter
      Something like this kracekumar@kracekumar-laptop:~$ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
    • 84. Interactive shell
    • 92. Interactive Shell cont . . .
    • 100. Interactive shell Cont . . .
    • 108. Math More
    • 116. Still more Interactive shell You can do more in interactive shell ,But you might be bored,so Lets start writing small scripts
    • 120. First program
      • Open first.py
      • 121. Run python first.py ,Your program will be interpreted and python will produce .pyc in memory .
      • 122. .pyc =>python compiled
      • 123. Duck typed programming language
    • 124. Interactive Shell (Revisited)
    • 133. Cont . . .
      • >>> c=2**890
      • 134. >>> c
      • 135. 8254602048994769474255309139320571976856989469314398783249386078541779727448825929287769623244643560854287421769642635607536680617229461519539671538483430889193541937484454440136429963694163141453503639190799818814812942074243152169349951543234944945149040326527156224L
      • 136. >>> len(str(c))
      • 137. 268
      • 138. Str() =>Find string length
    • 139. String
    • 151. Importing in built modules
    • 162. Strings are immutable
      • >>> name[0]="a"
      • 163. Traceback (most recent call last):
      • 164. File &quot;<stdin>&quot;, line 1, in <module>
      • 165. TypeError: 'str' object does not support item assignment
      • 166. >>> name
      • 167. 'kracekumar'
      • 168. >>> name=&quot;K&quot;+name[1:]
      • 169. >>> name
      • 170. 'Kracekumar'
      • 171. Above is a small hack to change the first character value in the name
    • 172. Slicing
    • 180. Python introspection
      • Python introspection lets you to find all builtin functions,classes etc. . .
      • 181. >>> dir()
      • 182. ['__builtins__', '__doc__', '__name__', '__package__', 'a', 'b', 'c', 'name', 'name1', 'name2', 'name3', 'sys']
      • 183. dir(anyname) =>will yield all the supported functions.
    • 184. In Built help
      • help(anyname)
      • 185. >>> help(a)
      no Python documentation found for '123' #here no documentation is available so you won't find
      • help(sys)
      Find the magic here :)
    • 186. Data structure
      • 3 in built data structure
      • 187. List => a=[1,”linux”,2,”Free Bsd”]
      • 188. Tuple => b=(1,”apple”,mango)#mango is not quoted because here it refers variable
      • 189. Dictionary =>dict={”name”:”kracekumar”,”email”:” [email_address] ”,”coll”:”Amrita”}
      • 190. Don't worry guys you have array but i will introduce later
    • 191. Data structure
      • >>> a
      • 192. [1, 'linux', 2, 'Free Bsd']
      • 193. >>> b
      • 194. (1, 'apple', 'mango')
      • 195. >>> dict
      • 196. {'coll': 'Amrita', 'name': 'kracekumar', 'email': 'kracethekingmaker@gmail.com'}
      • 197. List is not linked list here
      • 198. You can have string ,int,float in list,tuple,dictionary
    • 199. Data structure in python
    • 206. Cont . . .
    • 213. Cont . . .
      • >>> b[1]
      • 214. 'apple'
      • 215. >>> b[1]=&quot;pine apple&quot;
      • 216. Traceback (most recent call last):
      • 217. File &quot;<stdin>&quot;, line 1, in <module>
      • 218. TypeError: 'tuple' object does not support item assignment
      • 219. >>> b
      • 220. (1, 'apple', 'mango')
    • 221. Dictionary
      • >>> dict
      • 222. {'coll': 'Amrita', 'name': 'kracekumar', 'email': 'kracethekingmaker@gmail.com '}
      • 223. coll =>is key and 'Amrita' =>value
      • 224. All key should be unique
      • 225. >>> dict['coll']=&quot;ASE&quot;
      • 226. >>> print dict
      • 227. {'coll': 'ASE', 'name': 'kracekumar', 'email': 'kracethekingmaker@gmail.com'}
      • 228. >>> dir(dict)
    • 229. Dictionary functions
      • dir() and help() will help you to know more about list tuple
      • 230. dir(dict)
      Try
    • 234. Control Flow if guess == number: #do something elif guess < number: #do something else else : #do something else while True : #do something #break when done break else : #do something when the loop ends for i in range( 1 , 5 ): print (i) else : print ( 'The for loop is over' ) #1,2,3,4 for i in range( 1 , 5 , 2 ): print (i) else : print ( 'The for loop is over' ) #1,3
    • 235. Program
      • Wap to find a no is prime or not
      • 236. List comprehension
      • 237. E.g >>> x=[y for y in range(0,20) if y%2 == 0]
      • 238. >>> x
      • 239. [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
      • 240. Alternate way to do
      • 241. Open list_comp.py
      • 242. Dictionaries,list,tuple can be nested
    • 243. Functions
      • Order is important unless using the name
      • Default arguments are supported
      def sayHello (): print ( 'Hello World!' ) def foo (name, age, address) : pass foo( 'Tim' , address= 'Home' , age= 36 ) def greet (name= 'World' )
    • 244. Functions
      • Variable length args acceptable as a list or dict
      def total (initial= 5 , *numbers, **keywords): count = initial for number in numbers: count += number for key in keywords: count += keywords[key] return count print (total( 10 , 1 , 2 , 3 , vegetables= 50 , fruits= 100 ))
    • 245. Functions def printMax (x, y): '''Prints the maximum of two numbers. The two values must be integers.''' x = int(x) # convert to integers, if possible y = int(y) if x > y: r eturn x else : r eturn y printMax( 3 , 5 )
    • 246. Last important thing about variable
    • 254. File Handling
      • Wap to read input from user and write back to file . =>fav_movie.py
      • Wap to read set of numbers and write to file and read the file and add all the nos.=>pickling.py
      • Swap 3 nos
    • 255. Practice problem
      • Get a particular line from a file = >get_particular_line.py
      • 256. Get a list of zip file content and its size =>zip_length.py
      • 257. Get current system name and ip=>details.py
      • 258. Generate a random password using python
    • 259. Modules
      • Any python file is considered a module
      • 260. Modules can be imported or run by themselves
      if __name__ == '__main__' : print ( 'This program is being run by itself' ) else : print ( 'I am being imported from another module' )
    • 261. Recursion
    • 269. OOPs
      • Python OOP is easy and simple
      • 270. Class classname:
        • Def name():
      Objects
    • 275. Inbuilt functions
      • hasattr(obj,attr)
      • 276. getattr(obj,attr)=>retrieves attr value
      • 277. setattr(obj,attr,val)=>set attr value
      • 278. delattr(obj,attr)
      • 279. first_class.py
      • 280. add_book.py
    • 281. More Resources
      • http://wiki.python.org/moin/BeginnersGuide
      • 282. http://www.python.org/doc/faq/
      • 283. Learn Python in 10 minutes: http://www.poromenos.org/tutorials/python
      • 284. Byte of Python: http://www.swaroopch.com/notes/Python
      • 285. Dive Into Python: http://diveintopython.org/
      • 286. Google
    • 287. Any Questions ???
    • 288. Thank You