Getting Started with Python | CMD TO
Getting started with Python is a surprisingly easy process. You will love how simple
this programming can be and how it will work on a lot of different programs. It is
simple enough for the beginner to read through, once they learn some of the tricks of the
trade, but it still has the power that you want when working on a programming language.
It has the best of both worlds, which is why this programming language is one of the best
options out on the market to choose from.
What is Python?
Python is a high level programming language that will use Object Oriented
Programming, or OOP. It is often used as a glue language to help connect other
components together and can be used as a general purpose programming language.
Because it is so versatile, it can be used with some of the more powerful programming
languages, and easy to read, it gets rid of some of the brackets and other messy stuff that
is in other languages, it has been ranked as one of the most popular languages for
programming in the whole world.
If you are looking to create things like scripting interpreters, web applications, and even
applications on the desktop, Python is the best program for you. It is considered open
source right now, meaning that no one owns the rights to using it exclusively. This
provides you with many different choices with the language as anyone can take the code
and make it better all throughout the world. The best part is, it is powerful, can be
placed on many different computers and computer systems, and it is free.
Versions of Python
There are a few different versions of Python that have come out over the years and they
all have some different benefits as to why you should choose them. The most updated
one is Python 3, although there are a few versions of this out right now. Most
professionals are still using Python 2 because it is able to go back and work with older
versions if needed while Python 3 is not able to do this. There are no newer versions of
Python 2 that have come out in the past few years so it is likely that it is going to be
phased out soon and Python users will have to stick with their older version or choose
Python 3.
The original create of Python, Guido van Rossum choose to develop this language
because it was simple, based on the English language, so that programmers new and old
would be able to use the program without having too much complication. The language
has undergone many changes throughout the years, especially since it has become open
sourced for other companies and individuals to work with, but it has still maintained its
simplicity and ability to work well with people who are new to programming.
Downloading Python
Let’s have a little refresher course on how to download and install the Python program
for those who may not have this program on their computers. You can download this
program by visiting www.python.org/downloads or you can pick one of your favorite
distribution sites and download the version that you want. You will need to select the
python windows installer and then follow the simple steps that follow.
You should notice that the setup wizard will come up; it is easiest to just click on “Next”
for all the options during the following steps in order to get everything to show up in
default. If you would like to customize some things or make some changes, you are able
to select these as well when going through the setup.
After Python has been successfully installed on the computer, you should select IDLE in
order to get started. This is basically going to be the part that allows you to work on
Python so you need to make sure that you have it opened so that you can start writing
your code. You will also need a text editor to work with so that the program is able to
go through and read the work that you are doing. For a Windows computer, working with
Notepad is a great option or you can pick out another option online.
How does Python Execute a Program
Each programming language that you work with is going to execute a program a bit
differently. This is why it is so important to learn how to organize the words and the
different statements that the program requires so that you avoid errors and other issues in
your code. In this chapter, we will take some time to learn how Python will execute the
commands that you give and basically how the whole program runs.
When you are working with Python, you are working with an interpreted programming
language. You will have a text interpreter that will execute each of the programs going
line by line and then will convert it into a code for the process to understand the words
and carry them out for you.
Python is also a scripting language, so you can write out the script and then save it using
the extension .py or you can directly write it and then execute each statement into the
Python shell.
Internally, Python is going to work to compile your program, basically the source code,
into a byte code that has the .pyc extension, just like the Java byte code. This makes it
easier for the code to be executed without the delays and you will be able to see it come
up in just a few seconds rather than waiting around.
You will be able to save your byte code files into a subdirectory that is called
__pycache__ which is located in the directory where the source file resides. For
example, if you wrote out helloworld.py it is going to then be converted into one of
these byte codes and renamed helloworld.pyc.
You can go in and manually compile this code if something does go wrong, but for the
most part, Python is going to do the compilation for you so it won’t be an issues. As a
beginner you may wonder where some of these .pyc suffixes come from, but Python is
going to store them with that specific suffix so don’t worry if it shows up.
Of course, this is only going to happen if Python has the write access, but even if the
Python has no write access, it may not be saved that way, but the program is still going
to work.
Whenever you call up a Python program, Python is going to check if there is already a
compiled version with this .pyc suffix. This file should be newer than the .py suffix and
if it exists, the Python will load in the byte code to speed up how fast the script is able
to go. If the byte code doesn’t exist on your computer, Python will work to create your
byte code before it executes the program.
So basically, each time that you execute a script in Python, you will have a byte code
created by the program as well. If the script in Python is imported like a module, your
byte code is going to be stored in the proper .pyc file.
Python Implementations
When you hear about implementation of Python, it means that the environment or the
program that is providing support for executing your programs inside of the Python
language, will be represented with the CPython reference implementation. This means
that it is going to help you to work on executing the different codes and statements that
you are working on within the program. There are also some variants of the CPython that
you can work on and will make a big difference in the way that the program works.
Some of the features that are available with the variants include:
CrossTwine Linker—this is going to be a combination between CPython and an
add-on library of your choice. It is going to offer some better performance when
it comes to the code that you are working on.
Stackless Python—this is CPython that has an emphasis on concurrency while
using channels and tasklets. This is often the kind that is used for the dspython on
programs like the Nintendo DS.
Wypthon—this is considered a re-implementation of some of the parts of Python,
which will drop the supports of using bytecode in order to use the wordcode
based omdel. It is going to use the stack register in the implementation and adds
in lots of other types of optimization.
Implementation is everything when it comes to how you are able to work on your
programs and can help you to get more done with Python compared to some of the other
programming languages. What is so unique about Python is that it is able to work with a
lot of other programming languages in order to still be simple to work on the code plus
has all the power that you need to really get things done. Some of the other
implementations that you may want to consider if you want to do something specific with
the Python programming language include:
Brython—this is one of the implementations that you can use in order to run
Python in your browser using a translation to JavaScript so you can use these two
together.
CLPython—this is an implementation of Python in common lisp.
HotPy—this is considered a virtual machine for Python that will support
translation and bytecode optimization.
IronPython—this is Python in C#. C# is a great programming language to use
inside of the Windows platforms and is often a competitor to Python based on
how popular and easy it is to use. This implementation allows you to translate
your work from Python over to C# if you choose.
Jython—this is the version of Python available for the Java platform.
PyMite—this is Python that you can use for embedded devices
PyPy—this is Python within Python so that you are able to target a few different
environments at the same time.
RapydScript—this is a language that is similar to Python that will compile into
JavaScript so that you can use it in the Java platform without having to go with all
of the difficult language issues.
Working on Python can be a great experience. If you are just a beginner with the idea of
programming and are unsure about how to get all of this started, some of the other
programming languages can be a bit confusing. Python is easy to use but has all the
power that you want from some of the bigger names in programming language and you
get the benefit of getting to use this program along with some of the other popular
languages that you may want to work with!
Review of a Simple Program
As we mentioned, using Python is one of the simplest programming languages that you
can choose. It isn’t going to have a lot of excess around it like some of the other
languages, which can save you a lot of time and effort.
It also makes it easier for you and for someone else to take a look at the information and
be able to read through it. So let’s take a look at some of the things that you can do with
Python and how to get started with writing your first program.
The first program that we are going to write out is the “Hi World” program. This one is
going to need a Python shell to make it easier and you will be able to test it out on your
editors if you do it properly. This makes it easier to have a good idea of what you are
doing and to catch any errors right in the beginning. If you are using the Python Shell,
which works well on most of the computer types and programs that you may be using
with Python, you will simply need to type in the following program to get the
information to show up:
Print(“Hi World!)
You should be able to go and execute this information and find that it will show up with
the words Hi World! On the screen. This is a simple process to do, but it is going to help
you to get things started and provides a good review of some of the simple steps that you
need in order to start writing your own program on Python.
Remember that Python is a really easy programming language that won’t have a lot of
different brackets and other information that is in the way and will slow down what you
are doing. It is also really easy to read.
As you can see, you only needed a few things in place in order to write out the phrase,
rather than needing to type out lines of code to get the same result like you would need to
do with other programming languages. Let’s take a look at some of the other things that
you are able to do with Python programming and how you can even write some good
code to get your programs started.
No comments:
Post a Comment