Python is an object-oriented language, just like Javascript, C++, C#, Perl, Ruby, and other key programming languages. For people planning to become software developers, learning this type of programming in one area will help you adapt easily in other environments.
Python is intended to be a highly readable language, see the following examples :
For loop in Python
# This is a python comment
items = [1,2,3,4]
for i in items:
print (i)
While loop in Python
x=1
while x <= 5:
# Convert the number to string using the str method
print "The number is:" + str(x)
x += 1
As you can see, it is designed to have an uncluttered visual layout, often using English keywords where other languages use punctuation. In this post you'll learn to set up a minimalist development environment with Python for windows.
Download a Python distribution for windows
To download the latest distribution of Python for windows, go to the Download page in the homepage here.
Note that in the homepage, you'll find which version you'll want to download. In python there are till the date 2 versions, 2x
and 3x
, but, should I use Python 2 or Python 3 for my development activity?.
Python 3.0 was released in 2008. The final 2.x version 2.7 release came out in mid-2010, with a statement of extended support for this end-of-life release. The 2.x branch will see no new major releases after that. 3.x is under active development and has already seen over five years of stable releases, including version 3.3 in 2012, 3.4 in 2014, and 3.5 in 2015. This means that all recent standard library improvements, for example, are only available by default in Python 3.x.
In particular, instructors introducing Python to new programmers should consider teaching Python 3 first and then introducing the differences in Python 2 afterwards (if necessary), since Python 3 eliminates many quirks that can unnecessarily trip up beginning programmers trying to learn Python 2.
Read more about the differences here. In this case, we are going to download the 3x version. Finally, when the installer has been downloaded, go to the next step.
Install the distribution
Execute the installer according to your version the setup may vary :
Note that is important to check "Add Python 3.5 (or any version) to PATH". Of this way, python keyword will be available to use in the command prompt (cmd.exe) and you'll be able to do everything with python from the command line.
Important : If you uncheck this feature, or later if the python variable is not available in the cmd.exe
, you'll need to setup the system path variable.
You can obviously change the configuration in the way you want (another drive, choose only a couple of features etc).
Continue with the installation normally till the end (setup was succesful).
Adding Python to System Path Variable
Note: If you decided to use the Python >= 3.4
, you will not need to follow this process, you can simply skip ahead to the hello world section.
Begin by opening the start menu and typing in “environment” and select the option called “Edit the system environment variables.”
When the System Properties window appears, click on Environment Variables :
Once you have the “Environment Variables” window open, direct your focus to the bottom half. You will notice that it controls all the “System Variables” rather than just this associated with your user. Click on “New…” to create a new variable for Python.
Simply enter a name for your Path and the code shown below. For the purposes of this example we have installed Python 2.7.3, so we will call the path: “Pythonpath.”
The string that you will need to enter is: “C:\Python27\;C:\Python27\Scripts;”
. Note that according to your version and the installation path, this value needs to be changed.
Press OK to everything that appears to accept all changes and exit the “System Properties” window.
Now Python path would be available in the cmd.exe.
Hello world
Now that python has been succefully installed in our system, we just need to use it.
There are 2 ways to achieve your first Hello World with python in windows
1) Open the python shell (IDLE).
And execute the following line on it :
print ("Hello Python World in Our Code World <3");
Congratulations, you've just said hello to the world in python !. On the IDLE you'll be able to execute python code live, you can play with more examples on it, for example use the math class to know if something is not a number (NaN
).
2) Execute python with cmd.exe
Open the command prompt of windows (cmd.exe) and type python on it.
After typing python the information about python will be listen and you'll be able to execute python from the command line. Now type the following line while python is active :
print ("Hello Python World in Our Code World <3");
Congratulations, you've just said hello to the world in python.
Have fun with Python