What is Python?
Python is a high-level, general-purpose language. The first release of Python was 1991, 24 years ago. It was designed as simple as possible. May for this reason all Linux and Mac OS’s have Python installed.
What can we do with python?
Perhaps it is easy to say, we can crack the whole world with Python. I have given a short-listing of Python uses –
1. Unix and Linux System administration
2. Web programming with Django, TurboGears, TurboGears, Flask, Pyramid etc.
3. Artificial Intelligence
4. Scientific Research
5. Game Programming
6. Natural Language Processing
7. Image Processing
8. Machine Learning
And many more…
At this moment there are two versions of Python available, 2.x and 3.x. 3.x version has some update. But you will found most of the module has support at least 2.7.x version. So, we will learn on Python 2.7.x version.
If you are using Mac or Linux then you already have Python installed. Check your python version from command prompt –
Yes I have Python 2.7.10. But the real fun is, you can use both the version in your workstation.
If you like this just download and install 3.x version in your Mac or Linux from https://www.python.org/. As simple, as it is.
But for Windows user choose one, download and install. And check your python version from command prompt.
For writing Python code we need a text editor better if we say IDE. My choice is PyCharm. It has free community edition. But you can use Eclipse IDE with pyDev installed. Or a very simple text editor like Notepad++, TextWrangler etc.
There is an interpreter comes with Python, called Integrated Development Environment (IDLE). Just go to the command prompt and type “python” or “python3”, the IDLE will show up –
You can write your code in here as well.
Lets write our first program called hello world. Create a file named hello.py anywhere in your workstation and write the following code –
print "Hello World!!!" print("hello...") print "Hello"+" World"+"!!!" print "Hello", " World", "!!!"
Now from the command prompt write –
Easy right!!! We are just seeing 4 ways of printing hello world. Line 5 and 7 is the way we will glue together number of strings.
Let’s create one Python script called var.py and write the some code –
a = 3 b = 5 c = d = 8 e, f, g = a, b, 9.9 print "a = %d" % a print "b = %d" % b print "c = %d" % c print "d = %d" % d print "e = %d" % e print "f = %d" % f print "g = %f" % g
a = 3
b = 5
c = 8
d = 8
e = 3
f = 5
g = 9.900000
Assigning the value of a and b is simple. c and d have the same value and in line 6, we can assign values for multiple variables with this way in Python. Rest of are simple printing. %d for integer, %f for float and %s for string, remember.
Let’s take some user input. Create a new file with the name input.py in your directory.
firstName = raw_input("First Name: ") lastName = raw_input("Last Name: ") print "" print "" print "Hello %s %s!!!" % (firstName, lastName) print "Is this fun!!!"
Then run it from command prompt with “python input.py” and check the output.
In line 1 and 3 we are using raw_input() function to take user input.
All codes are available in my git repository.
Having fun with Python? A lot more surprise is coming on. I have a plan to write on from system programming to web with Python in this series. So keep reading.
Happy Coding… 🙂
Getting Started Python
Hej, I’m from Bangladesh. Learning programming is one of the freaking decisions I have taken in my life. Because, it makes me and my life crazy. I have great weakness on open source technologies. Perhaps, that’s why I do not know any closed source language. I fall in love with programming, when I started my undergraduate in East West University. Till now, I can not live without it.