90 likes | 109 Views
Python is a versatile language with simple syntax, dynamic typing, and automatic memory management. It is widely used in diverse fields such as scripting, software development, and game programming. Learn about its history, concepts, and implementations in this comprehensive guide.
E N D
Python Henry Armstrong Andy Burras Everett Hite
History • First released in 1991 by Guido van Rossum • Designed around a philosophy which emphasized readability and importance of programmer effort over computer effort • Minimalist syntax and semantics • Large standard library is comprehensive • It was influenced by ALGOL 68, C, Lisp, Perl and Java • It was originally developed for UNIX scripting, but eventually grew beyond these bounds
Concepts • Multi-paradigm language focusing on functional, object oriented and imperative • Has a fully dynamic type system. This means that type checking is done during runtime • Variables are strongly typed. This forbids operations which make little or no sense (i.e.; cannot perform int + char) • Has automatic memory management • Has a highly readable, uncluttered language. Uses many English keywords where other languages use punctuation
Implementations • YouTube and the original BitTorrent client were programed in python. • Google and NASA use python for a variety of things • Python is embedded in a number of software packages including ArcGIS (a GIS package) and Maya (a high-end 3D animation package) • Python is also used for scripting in a number of video games, including Civilization IV, Eve Online and Battlefield 2
Code Example print "This is a factorial program.“ n = -1 #Initialize n for error checking while n < 0: #Ensure that only nonnegative numbers will be accepted n = input( "What number do you want to factorialize?" ) temp = n #Initialize return value (temp) and the counter count = n – 1 if n == 0: #Account for special case 0! = 1; set temp, count to 1 temp = 1 count = 0 while count > 0: #Calculate n factorial temp = temp * count count = count – 1 print n,"! =",temp #Print result
Comparison to Other Languages The following programs will count from 0 to 1000000 and print them out to a file Java: import java.io.*; public class test{ public static void main(String[] args){ try{ File f = new File("/tmp/scratch"); PrintWriter pw = new PrintWriter(new BufferedWriter( new FileWriter(f))); for(int i = 0; i < 1000000; i++){ pw.print(i); } pw.close(); } catch(IOException ioe){ ioe.printStackTrace(); } } } Python: f=open(‘/tmp/scratch’,’wb’) For i in xrange(1000000): f.write(str(i)) f.close() C++: #include <iostream.h> #include <fstream> using namespace std; int main(int argc, char *argv[]){ ofstream out; out.open("/tmp/scratch"); for(int i = 0; i < 1000000; i++){ out << i; } out.close(); }
Comparisons (cont’d) To Java: • Python typically run slower than equivalent Java programs • The development process for Python is significantly shorter than that of Java • Actual code length of Python is 3-5 times shorter than equivalent Java code To C++: • Python compared to C++ is similar to Python compared to Java, just to a greater extent. • Actual code length of Python is 5-10 times shorter than equivalent C++ code • Python is sometimes referred to and used as a glue language that combines several component written in C++ To Perl: • Both share similar roots (Unix, scripting), and similar features. • Perl is harder to maintain based off the sometimes cryptic syntax and multiple operators
SOURCES http://www.razorvine.net/python/PythonComparedToJava http://www.wikipedia.com/Python_(programming_language) http://furryland.org/~mikec/bench http://www.python.org