First cup of python

I decided to take my first cup of python. I decided to learn python because I would like to realize the full potential of Ubuntu. I chose netbeans.

The download is amazingly small. It is only a 30 MB shell script. Remember to grant execution rights before by typing ‘chmod +x’ before executing the shell script.

My First Hello World

Hello world is the first code that most programmers writes when the started learning a new language. Writing Hello World in java is:

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

In Python:

print "Hello World"

will do the trick.

Working with list

This is how we define a list in python:

daysInAWeek = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]

Printing the list only takes

print daysInAWeek

This will gives you:
[‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’, ‘Sunday’]

In java I will write this

public class ListPrinter

     public static void main (String [] args)
           String []  daysInAWeek = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};

           for(String day: daysInAWeek)
                 System.out.println(day + ",");

What day is today ?

Date manipulation is a common programming task. This is how you would get today date in python:

print "What day is today ? Today is : ",

This prints out What day is today ? Today is: 2010-01-23

A similiar implementation in Java will be:

public class DateSeer
     public static void main (String [] Args)
          Calendar cal = Calendar.getInstance();
          Date todayDate = cal.getTime();

          String dateFormat = "yyyy-MM-DD";
          SimpleDateFormat simpleDateformat = new SimpleDateFormat(dateFormat);
          System.out.println(simpleDateformat.format(todayDate ));

I am curious to explore how to use NetBeans to import classes. I always use ‘ctrl + shift + o’ to do this in eclipse. I have not found out how to do this in Netbeans yet.

About zainul franciscus

Hi, I am a software developer and tech blogger who is currently living in Wellington, New Zealand. I write stuff that I find interesting on
This entry was posted in java, programming, Python and tagged , , , . Bookmark the permalink.

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s