Python

by Dhruv Baldawa

http://www.dhruvb.com/

@dhruvbaldawa on twitter

Show me the code!

'coz code speaks louder than words

Hello World

Python


        print "Hello World"
    

C++


    #include <iostream>
    using namespace std;
    int main (int argc, char** argv)
    {
        cout << "Hello World!";
        return 0;
    }
        

Java


    public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello World");
        }
    }

        

Reading a file

Python


    for line in open("filename"):
        print line
    

C++


    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    int main () {
        string line;
        ifstream myfile ("filename");
        if (myfile.is_open()) {
            while ( myfile.good() ) {
                getline(myfile,line);
                cout << line << endl;
            }
            myfile.close();
        }
        else cout << "Unable to open file";
        return 0;
    }
    

Reading a file

Java


    import java.io.*;
    class FileRead {
        public static void main(String args[]){
            try{
                FileInputStream fstream = new
                FileInputStream("textfile.txt");
                DataInputStream in = new
                DataInputStream(fstream);
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                String strLine;
                while ((strLine = br.readLine()) != null)   {
                    System.out.println (strLine);
                }
                in.close();
            }
            catch (Exception e){
                System.err.println("Error: " + e.getMessage());
            }
        }
    }
    

Swapping

Wait for it !

a, b = b, a

Now you have some idea about the language

How about some cool demos ?

Demo 1

Visualizations

Demo 2

A Search Engine

Demo 3

A Web Application

Demo 4

Scripts which talk to the internet

FAQs

What is it ?

Who is using it ?

Who wrote it ?

How fast is it ?

Which platform does it run on ?

What can I do with it ?

What are the data types ?

About Python

  • created by Guido van Rossum
  • named after BBC show "Monty Python"
  • first version released in 1989
  • consistently ranked in top 8 most popular language since 2008
  • won 2007 and 2010 "Programming Language of the Year"

Who is using Python ?

Courtesy: PyCon US 2012 website[6]

Who is using Python ?

  • Google
  • YouTube
  • Dropbox
  • Yahoo
  • NASA
  • Nokia
  • IBM
  • CIA
  • Disqus
  • Walt Disney
  • ... and many more

Where can I run Python ?

Where can I run Python ?

  • works on Windows, Linux and MacOSX.
  • also works on Nokia Series 40 and Series 60.
  • There are Python interpreters and packaging for Android.
  • Python interpreters are also available for iOS.
  • There are also various projects regarding running Python in browser.

What can I do with Python?

  • Web Development
  • Database Access
  • Desktop GUIs
  • Scientific and Numeric computing
  • Network programming
  • Games and 3D graphics
  • Embedded systems
  • ... sky is the limit !

Why Python ?

  • free and open source
  • cross platform
  • clear and readable syntax
  • rapid application development
  • "batteries included" with a great "standard library"
  • works great with C, Java, .NET and other technologies
  • automatic memory management and garbage collection

Why Python ?

  • significantly reduces development time and source code size.
    • usually 3-5x shorter than equivalent Java programs
    • usually 5-10x shorter than equivalent C++ programs
  • helps the developer focus on code
  • excellent language for prototyping
  • ... and many more

Why not Python ?

  • often just considered as a scripting language
  • slower than compiled languages
  • slower parts can often be compiled to C, to make them fast

Where can I learn Python?

Everybody is using Python to teach Programming

Where can I learn Python?

“Udacity’s courses so far have been using Python because it is overall, the most convenient language for teaching and learning. The natural syntax means students spend less 6me grokking code than with terser languages.”
-- Chris Chew, Software Engineer, Udacity Inc.[3]

What next?

Questions ?

Contact me at: http://www.dhruvb.com/

Submit feedback: http://www.dhruvb.com/pyfeedback

References

  1. http://wiki.python.org/moin/OrganizationsUsingPython
  2. http://www.python.org/about/
  3. http://blog.udacity.com/2012/05/learning-to-program-why-python.html
  4. http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
  5. xkcd 353
  6. Sponsor logos on PyCon US 2012