Upload
dhanashree-prasad
View
59
Download
0
Embed Size (px)
Citation preview
BITS PilaniPilani Campus
Dhanashree N P
Lecturer (Off-Campus) Computer Science
'Hello, World!' with Python
04-01-2017
DISCLAIMER
This is NOT a Python programming tutorial!!
Session Overview
1. The clichéd title 2. Python & PSF3. Features of Python4. Success stories: using Python5. Sample programs 6. FAQs7. Python programs are ‘slow’ – Myth?8. Why is Python preferred by many?9. Reference Links
The clichéd titleAny programming tutorial starts with a ‘Hello, World!’ program. Let’s use the same to answer ‘Why Python?’
Python & PSF
• “hobby” programming project
• Interpreter for a scripting language
Dec 1989
• Python 2.0 – 16th Oct• Unicode Support, cycle-
detecting GC
Oct 2000• Python 3.0• Backward-Incompatible• Features backported to
backward compatible 2.7.x, 2.6.x
Dec 2008
Guido van Rossum – creator of Python – benevolent dictator for life (BDFL)
Python Software Foundation(PSF) - manages the open-source licensing for Python 2.1 and later - mission is to promote, protect and advance Python; support
and facilitate growth of international & diverse community of Python programmers. [2001]
Python: Features
6
Language Features
High-level
General Purpose
Multi-Paradigm
Interpreted
Fully Supported
• Object-oriented Programming• Structured Programming
Supported by Language
Features
• Functional Programming• Aspect Oriented Programming
Supported by
Extensions
• Design by Contract• Logic Programming
Python: Features
7
Features
Dynamic typing
Late binding
ExtensibleWhite Spaces
Automatic Memory
Management
The name Python was inspired from the series Monty Python’s Flying Circus
a = 3a = “a string”a = [‘a’, ‘list’]len(a)
Success Stories using Python
8
Web & Analysis• Mozilla• Google• Youtube• Bitly• ForecastWatch.co
m etc
Science, Energy• ExpEYES [portable
scientific laboratory]• VAMPZero [aircraft
conceptual design]• Eco Mode @ SMS
Siemag AG• Large Hadron Collider
(CERN)• EPRI (Life on Mars - ESA)
[Python powered clusters and graphics processing]
Animation & Graphics• Blender• Houdini
Systems Cloud, Data Centers etc.• Open Stack• Google App
Engine• Flying Circus• rackspace
Others• Scientific &
Numeric Processing – SciPy, NumPy
• Machine Learning & Analytics – SocialCorps, Innoplexus, Fractal Analysis
• Automation of applications [ Jython]Oracle in ODI
A few lines of code..
9Examples shown use Python 2.7.12
A simple word-count program – Python shell/command line
A simple word-count program using the os module – Python shell/command line
A few more lines of code..
10Examples shown use Python 2.7.12
Code to check the word count limit for multiple files
Save this code in a file as pgm.pyFrom the command line (Linux) – execute it using: python pgm.pyOr from within IDLE shell - execfile('pgm.py')
A few FAQs
11
1. What version to choose – 2.7.x or 3.x? https://wiki.python.org/moin/Python2orPython3
2. What to use for development?1. Any text editor (from notepad to Sublime Text)2. IDE (Eric, Pycharm) 3. Online Web Application: Jupyter (iPython)
3. How to run?1. Use the command line python filename [arguments]2. Use the Python shell execfile(filename[,arguments])
4. How to debug? pdb module https://docs.python.org/2/library/pdb.html
Is Python ‘slow’ ? Why?
12
Yes – most of the raw code is slower than C/C++. But it is faster than Ruby/JavaScript [Source: Internet]
A few reasons are:1. Dynamic v/s Static typing2. Interpreted v/s Compiled3. Inefficient memory access due to its object model (list
access)
But there are hacks to overcome these: vectorised operations [SciPy, NumPy etc.], calling compiled code, using specific libraries etc.
Read more at: https://jakevdp.github.io/blog/2014/05/09/why-python-is-slow/
Why not something else?
Source: https://www.python.org/about/
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Questions?
Source: https://www.explainxkcd.com/wiki/index.php/353:_Python
BITS Pilani, Pilani Campus
Python – About, Documentation, Downloads etc. - https://www.python.org/Python Software Foundation - https://www.python.org/psf/Logos and Usage - https://www.python.org/community/logos/History and Timelines -
https://en.wikipedia.org/wiki/Python_(programming_language)Some Success Stories and Case studies -
http://brochure.getpython.info/media/releases/psf-python-brochure-vol.-i-final-download.pdf/at_download/file
Some Tutorials/Books to start with: The Python Tutorial https://docs.python.org/3/tutorial/
LearnPython.org http://www.learnpython.org/Think Python: How to Think Like a Computer Scientist – Allen. B. Downey http://www.greenteapress.com/thinkpython/html/Python Playground: Geeky Projects for the curious Programmer – Mahesh Venkitachalam https://www.nostarch.com/pythonplayground
Reference Links
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 195617
Thank You!