Home > Other programming languages > Python: Prosssss and Conssss

Python: Prosssss and Conssss

Python

Image by Aoife Cahill via Flickr

Hello there!

I know I haven’t been posting very often recently, but I hope to remedy that.  Today, I’ll be talking about the pros and cons of Python.

First of all, what is Python?  Well, it is a programming language that, at first glance, seems like some sort of C or Java.  It is case-sensitive (thus everything is pretty much lower case), it is dynamically typed (meaning that you don’t have to declare variables) and it’s pretty general purpose.

But what makes Python unique?  Well, for one thing, it doesn’t use those curly bracket thingies ({}) for blocks.  Instead, it uses only indentation!  For example:

def main():
   spam = 7
   eggs = 6
   print spam * eggs

That is a basic function.  As you can see, there is no “end def” or even curly braces.  Instead, it just uses the colon character to tell where a block begins, and indentation to see where the block ends.

The second thing that’s different about python, as you can see, is that there is no foo, bar, or even a baz!  Instead, the metasyntactic variables are spam and eggs.  “Why?”  I hear you ask.  Because the creator of Python, Guido van Rossum, has a sense of humor.  The language, is, in fact, not named after the snake.  It is named after the british comedy, Monty Python’s Flying Circus.  And so these variables are derived from that famous sketch, Spam.

One other thing I like about Python is that you can switch the values of any number of variables around in one line of code.  For example:

spam = 2
eggs = 3
bacon = 4

spam, eggs, bacon = bacon, spam, eggs   # Now spam is 4, eggs is 2, and bacon is three. (# is the character used for                                                                                                     # comments in Python.)
spam, eggs = eggs, spam                                # Now spam is 2 and eggs is 4.

The one thing that will throw beginners off in Python is the for statement.  It is not like the friendly VB For, nor is it like the fiendish C++ for().  It works more like this:

mylist = ["My", "head", "is", "large"]

for x in mylist:
   print x
for x in range(5):
   print x*2

The output:

My
Head
Is
Large
2
4
6
8
10

As you can see, the for loop can be hard to figure out.  However, all in all, Python is an excellent language, and I recommend it for VBers who are looking for a change of pace.  You can get it here: http://www.python.org/getit/

That’s all for today, but I hope to be posting more often, so see ya soon!

Advertisements
  1. LinuxGuy
    July 11, 2011 at 4:48 PM

    have you developed anything in python?

  1. April 19, 2012 at 2:42 PM
  2. November 17, 2011 at 3:21 PM

Your comment:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: