why python
DESCRIPTION
Presentation for why python should be the first language you learnTRANSCRIPT
![Page 1: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/1.jpg)
Why Python?Why Python?
By:By:Dr. Bessam Z. HassanDr. Bessam Z. Hassan
![Page 2: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/2.jpg)
CONTENTSCONTENTSWhy Python Should Be The First Programming Language Why Python Should Be The First Programming Language You Learn?You Learn?No Questions are DumbNo Questions are DumbSuccess Stories: Projects Completed with PythonSuccess Stories: Projects Completed with PythonStrengthsStrengthsSome ProblemsSome ProblemsComparing with Other LanguagesComparing with Other LanguagesConcluding RemarkConcluding Remark
![Page 3: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/3.jpg)
Why Python Should Be The First Why Python Should Be The First Programming Language You Learn?Programming Language You Learn?
Answer in three words: It’s awesome. That’s all you need to know. You can stop reading here and start coding now.
![Page 4: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/4.jpg)
Why Python Should Be The First Why Python Should Be The First Programming Language You Learn?Programming Language You Learn?
Of course, you want to know more. But it’s that simple. As you will see, you can literally start coding now with Python.
However, if you insist I will answer your curiosity
Programming• How many of you have programmed before?
• What’s the purpose?
• Solve something – get an answer to a problem• Make – create an app• Break – edit an app• Understand – how or why does it work?
![Page 5: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/5.jpg)
Why Python Should Be The First Why Python Should Be The First Programming Language You Learn?Programming Language You Learn?
Okay cool , but why Python?
• Solve something – straight forward• Make – simple to get started• Break – easy to read and edit code• Understand – modular and abstracted
Nah! still not convinced show me the money
• IT Salaries are up 1
• Python is the 4th top growing skill in the past 3 years
• Average starting Python programmer salary 2
• 70k+ per annum
Sources1 http://www.readwriteweb.com/enterprise/2011/05/it-hiring-and -salaries-up---wh.php2 http://www.payscale.com/research/US/Skill=Python/Salary
![Page 6: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/6.jpg)
No Questions Are DumbNo Questions Are DumbQ: I’ve never heard of Python. Is it popular?
A: Python is used in lots of cool places. Google, Industrial Light & Magic, YouTube, MIT and NASA (to name a few) all use Python. I think they know what they’re doing
Q: Are you serious?!!! How come no one told me? I thought those guys were using Visual C++, Java and Javascript. But again could it be just restricted to some places in industry or may be it is being used just in the US?
A: Python is used all over the world and not just in industry. It is being taught in the major engineering schools around the world. The correct question is not who is using Python. It is “who isn’t?”
Python Language Spread Across Engineering Schools Over the world
180 W 135 W 90 W 45 W 0 45 E 90 E 135 E 180 E
90 S
45 S
0
45 N
90 N
![Page 7: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/7.jpg)
No Questions Are DumbNo Questions Are Dumb
Sourcehttps://wiki.python.org/moin/SchoolsUsingPython
![Page 8: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/8.jpg)
No Questions Are DumbNo Questions Are DumbQ: Okay, but when I’m done with this course I’ll throw Python away and use something else, like C# or Java?
A: Only if you want to. Python might be the only programming language you’ll ever need. But, yes, if you want to learn another programming language, you can take everything you learn about programming inthis course and apply it to any other language with the minimum of effort.
Q: But a buddy of mine told me I should learn Java or C#. Why are younot using either of these programming languages in the introductory course?
A: Both Java and C# are great programming technologies, but they can be difficult to learn, especially when you are just starting out. This is not the case with Python. And, anyway, this is a course that’s designed to teach you how to program, and using Python as your first programminglanguage will help us to do just that.
![Page 9: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/9.jpg)
No Questions Are DumbNo Questions Are DumbQ: There seems to be many different versions of Python. Which one should I use?
A: There are two main releases of Python: 2 and 3. Python 3 is thefuture of the language; any new features are guaranteed to be added to release 3 of the language, not release 2. Of course, like all releases, Python 3 remains a free download, which makes it a no-brainerwhen deciding if you can afford to use it. REMEMBER Python is PLATFORM INDEPENDENT and OPEN SOURCE
Q: Will Python run on my phone, just like Java?
A: That really depends on your phone. Python is designed to run on lots of different technologies and operating systems. Running your own code on your own phone is a very specific requirement, and Java has that pretty well covered at the moment. As a programming technology, Java was initially designed to run on very small devices, so it is no big surprise that it is a strong and popular choice when it comes to telephony.
![Page 10: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/10.jpg)
No Questions Are DumbNo Questions Are DumbQ: Where does the name come from? Was the creator fond of snakes?
A: The name comes from Monty Python’s Flying Circuis. Yes, I know: it sounds silly, doesn’t it? And, believe me, it is. It’s funny, too. The creator of Python, Guido van Rossum, is a big Monty Python fan and reportedly watched the show’s reruns while he designed Python. You’ll find lotsof references to Monty Python folklore in the Python community. Dead parrots are a particular favorite.
Q: What makes it easier to learn?
A: Many features make the language easy to learn. My favorites are no begin and end commands, no curly brackets {}, no semicolon ; at the end of a command, very simple graphics, GUI and OOP support. Simply all works from the first attempt but the main thing about Python is that it has both interpreter and compiler so you get to see your mistakes right away
![Page 11: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/11.jpg)
Success Stories: Projects Success Stories: Projects Completed with PythonCompleted with Python
• Websites: Google, YouTube, Yahoo Groups and Maps, CIA.gov, Wikipedia
• Systems: NASA, LALN, CERN, Rackspace, Mars Lander
• Games: Civilization 4, Quark (Quake Army Knife)
• Mobile phones: Nokia S60 (Symbian), PythonCE
• P2P: BitTorrent
![Page 12: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/12.jpg)
StrengthsStrengths• Easy for beginners (all just works from the first time)
• … but powerful enough for professionals
• Clean and elegant code (merge between BASIC and elegance of C)• whitespace and indentation enforcement• automatic garbage collector for memory management
• Many modules and libraries to import from
• Free of charge open source
• Cross platform – Windows, Mac, Linux: It comes pre-installed with every Linux machine
• Supportive, large and helpful open source community
• Multi-paradigm: OOP, Structured, Functional, Aspect-oriented
![Page 13: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/13.jpg)
StrengthsStrengths
![Page 14: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/14.jpg)
Some ProblemsSome Problems• It is a scripting –like language with an interpreter. It works in two modes: development and runtime modes. After checking and trying your code for the first time it is compiled for the runtime. Hence it is a little bit slower than C/C++ in the first run. It is also slightly slower than Java but the speed becomes comparable in runtime mode
• Memory economy is hard to achieve (high-level data structures). This is a penalty of having the language readable and easy
• Multiprocessing and Global interpreter lock. Okay it wasn’t designed for multi-core so the development of the code will utilize a single core. However in runtime mode, the object code can make use of the multi-core
![Page 15: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/15.jpg)
Comparing with Other Comparing with Other LanguagesLanguages
![Page 16: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/16.jpg)
Comparing with Other Comparing with Other LanguagesLanguages
• Matlab supports matrices. Python supports scientific computing and scientific drawing • One helpful feature for scientific programming is the ability to put LaTeX equations and plots directly in code documentation. For example, if you want to put the following integral in your website
Then you need to put it as a picture were you can not alter, select or change the limits of the integral. However with Python you can write LaTex code in one line and the integral is interactive in your webpage
.. math:: \Gamma(z) = \int_0^\infty x^{z-1}e^{-x}\,dx
![Page 17: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/17.jpg)
Comparing with Other Comparing with Other LanguagesLanguages
• Including plots is easy. The following doc-string code:.. plot:: import numpy as np import matplotlib.pyplot as plt x = np.linspace(0,2, 1000) plt.figure() plt.plot(x, np.sqrt(x), label = r"Skiing: $\sqrt{x}$") plt.plot(x, x**2, label = r"Snowboarding: $x^2$") plt.title("Learning Curves for Snowboarding and Skiing") plt.xlabel("Time") ; plt.ylabel("Skill") plt.legend(loc='upper left') plt.show()
gives the following awesome plot for your report
![Page 18: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/18.jpg)
Concluding RemarkConcluding Remark
Sourcehttp://cacm.acm.org/blogs/blog-cacm/176450-python-is-now-the-most-popular-introductory-teaching-language-at-top-us-universities/fulltext
![Page 19: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/19.jpg)
Thank youThank you
![Page 20: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/20.jpg)
Python vs. C++ ExamplesPython vs. C++ Examples#include <iostream.h> main() { cout << "Hello World!"; return 0; }
Hello World in Python
Hello Worldin C++
print "Hello, world!"
![Page 21: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/21.jpg)
Python vs. C++ ExamplesPython vs. C++ Examples#include<stdio.h> #include<conio.h>
int fact(int );
int main( ) {
int a, f ; printf ( "\nEnter any number " ) ; scanf ( "%d", &a ) ; f = fact ( a ) ; printf ( "Factorial value = %d", f ) ; getch();
} int fact ( int x ) {
int f = 1, i ; for ( i = 1 ; i <= x ; i++ )
f = f * i ; return ( f ) ;
}
Output
Factorial in C++
![Page 22: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/22.jpg)
: Factorial: >>> Factorial() Enter any number: 5 Factorial value = 120
Python vs. C++ ExamplesPython vs. C++ Examples
print ': Factorial:\n' def Factorial():
a = input ('Enter any number: ') f=1 for i in range(1,a+1):
f=f*i print('Factorial value = %d'%(a,f)
Output
Factorial in Python
![Page 23: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/23.jpg)
RecursionRecursionRecursive function is a function that calls itself
Ex: Factorial
Fact(n)=n*(n-1)*(n-2)*…1 = n*[(n-1)*(n-2)*…1 ] = n * Fact(n-1)
Benefits of Recursion Extremely efficient memory managementFast execution timeElegant code
Some functions can be written recursively even if they are not recursive in nature
Ex: Square
Sq(n) = n2
Sq(n) = Sq(n-1) + 2n -1 = (n-1) 2+ 2n -1 = n2
![Page 24: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/24.jpg)
Python vs. C++ ExamplesPython vs. C++ Examples#include<stdio.h> #include<conio.h> int prime(int n) {
static int i=2; if(n%i==0 && n!=2)
{ return(1);
} if(i<n)
{i++;prime(n); // recursion call
} } int main(){
int p; printf("enter the number to check for prime number : ");scanf("%d",&p); int l=prime(p); //function returns the value and puts in 'l’ variable if(l==1)
//conditions printf("%d is not a prime number ", p);
else printf("%d is a prime number ", p);
getch(); }
Output
Prime Number in C++ Using Recursion
![Page 25: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/25.jpg)
Python vs. C++ ExamplesPython vs. C++ Examples
i = 2 def prime_number(n):
global i if (n % i == 0 and n>i):
return True if(n > i):
i = i + 1 return prime_number(n)
def main(): p = input('Enter the number to check for prime number : ') get = prime_number(p) if(get is True):
print "%d is not a prime number" %p else:
print "%d is a prime number" %p
Output
>>> main() Enter the number to check for prime number : 31 31 is a prime number
Prime Number in Python Using Recursion
![Page 26: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/26.jpg)
10 Reasons why Python 10 Reasons why Python Rocks for Research Rocks for Research
by Prof. Hoyt Koepke: Programming by Prof. Hoyt Koepke: Programming lecturer at Washington State Universitylecturer at Washington State University
Sourcehttp://www.stat.washington.edu/~hoytak/blog/whypython.html
![Page 27: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/27.jpg)
About Hoyt KoepkeAbout Hoyt Koepke
• Tried many Languages: R, Swift, Ruby, Java, Sage, C++, C# and Matlab
• Dropped Matlab 4 years ago in favor of Python as primary language for coding research projects
• Spoiled by Python features he became an addict of Python
![Page 28: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/28.jpg)
Hoyt Koepke ReasonsHoyt Koepke ReasonsGiven Python libraries, many features in MATLAB that enable one to quickly write code for machine learning and artificial intelligence –primary area of research – are essentially a small subset of those found in Python.
After a day learning Python, he was able to still use most of the matrix tricks he had learned in MATLAB, but also utilize more powerful data structures and design patterns when needed.
![Page 29: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/29.jpg)
Hoyt Koepke ReasonsHoyt Koepke ReasonsHolistic Language Design
A perfect language for research is one that allows concise and direct translation from notepad scribbling to code.
The more barriers between generating ideas and trying them out, the slower research progresses. In other words, the less one has to think about the actual coding, the better.
![Page 30: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/30.jpg)
Hoyt Koepke ReasonsHoyt Koepke ReasonsHolistic Language DesignMATLAB’s language design is focused on matrix and linear algebra operations; for turning such equations into one-liners, it is pretty much unsurpassed. However, move beyond these operations and it often becomes an exercise in frustration. R is beautiful for interactive data analysis, and its open library of statistical packages is amazing. However, the language design can be unnatural, and even maddening, for larger development projects. MathCad and Mathematica are perfect for interactive work with pure math, they are not intended for general purpose coding or teaching programming paradigms.
![Page 31: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/31.jpg)
Hoyt Koepke ReasonsHoyt Koepke ReasonsHolistic Language DesignThe problem with the “perfect match” approach is that you lose generalization very quickly as you become task oriented
Python hits the sweet spot between generalization and dealing with specific tasks
![Page 32: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/32.jpg)
Hoyt Koepke ReasonsHoyt Koepke ReasonsReadabilityThe emphasis on readability is no accident. As an object-oriented language, Python aims to encourage the creation of reusable code.
Even if we all wrote perfect documentation all of the time, code can hardly be considered reusable if it’s not readable.
Many of Python’s features, in addition to its use of indentation, conspire to make Python code highly readable.
![Page 33: Why Python](https://reader034.vdocuments.us/reader034/viewer/2022051821/563db9e0550346aa9aa0ba3f/html5/thumbnails/33.jpg)
Hoyt Koepke ReasonsHoyt Koepke ReasonsBalance between High Level and Low LevelCython is a part of Python. It is an open library that works by first translating Python code into equivalent C code that runs the Python interpreted through the Python C-API. It then uses a C compiler to create a shared library that can be loaded as a Python module. Generally, this module is functionally equivalent to the original Python module and usually runs much faster. Cython allows one to write code for low-level hardware. This gives massive speedups, as typed variables are now treated using low-level types rather than Python variables. With these annotations, your “Python” code can be as fast as C – while requiring very little actual knowledge of C.