Python For Beginners - The Crash - Aaron Khan
Python For Beginners - The Crash - Aaron Khan
Step 6: Once you have started PyCharm up, you should see the following as
depicted in image 6.1. For the first startup, PyCharm asks you to accept
standard terms & conditions before you can use the program.
You can read through these or not, but in order to continue, check the box
that states you have read and accepted the terms of this user agreement. Once
checked, click ‘Continue’.
6.1: Accepting User Agreement
Step 7: The box you should see is an option for most programming software.
The software developers ask if you allow the software to send data on your
usage to help in bug-fixing etc. For more details, they allow you an option to
read more about it.
You can choose to provide this information or not, you still have full access
to PyCharm.
7.1: Data Sharing Agreement
Step 8: We are in the final stages of this installation process. The few steps
are more preference steps than anything else. Once completed, you are ready
to move, where we will create a project for coding in.
Choose a theme for your UI. I will be using Darcula, but you can use
whichever. Once selected, click ‘Next: Featured plugins.
8.1: Theme Choosing
8.2: Featured Plugins
Once more, these are preference options. These plugins are more for the
experienced program and all are optional.
I won’t be using any additional plugins, so once you are ready, click ‘Start
Using PyCharm’
8.3: Finished and Ready to Start Creating Projects!
With that, you have finished installing and setting up PyCharm!
If you see the image in 8.3, you are ready to start where we will create a
project. An important last step before we start learning some code!
Chapter 4: Using the Python Shell, IDLE and
Writing the First Program
Once you have Python in your operating system, the following step is to
compile and run a program with Python.
A program is a series of instructions that have been coded and that will allow
you to perform a series of specific tasks on your computer. These coded
instructions are what are known as source code; these codes are what the user
or programmer sets in his computer.
The source code is written in the Python programming language and this
language will be converted into an executable file and for this to happen, in
other words, for the source code to be converted into an executable file, the
help of a compiler will be necessary that will be executed in a "central
processing unit" (CPU) and all this will happen with the help of an
interpreter.
In summary, we have that a compiler is going to convert our source code into
an executable file since it is a translator that transforms a program or source
code into a machine language so that it can be executed; this translation
process is what is known as compiling.
There is a difference between a compiler and an interpreter since the first one
translates a program described by the programming language into the
machine code of the system, while the interpreters only perform the
translation, be it instruction by instruction, and also do not store the result of
this translation.
Therefore, we have a source code that is going to be executable in two ways
by either a compiler or an interpreter who will execute it immediately.
When we open the IDLE in our system, in the same way that we did it before,
we are going to observe the screen that we find when we open our IDLE,
which is called Shell, or we can also call it as the interpreter of our Python
language.
Every time we open our interpreter or Shell, we will always find a kind of
header, which will always be the same, where it has Python information, such
as the version in which it is working, date and time, for example. This type of
format helps us appreciate that we are working with the Shell interpreter.
By means of this example, we will be able to visualize how our Shell
interpreter is doing the translation from Python language to machine
language instruction by instruction.
The default on OS X is that Python 3 is not going to be installed at all. If you
want to use Python 3, you can install it using some of the installers that are on
Python.org. This is a good place to go because it will install everything that
you need to write and execute your codes with Python. It will have the
Python shell, the IDLE development tools, and the interpreter. Unlike what
happens with Python 2.X, these tools are installed as a standard application in
the Applications folder.
You have to make sure that you are able to run both the Python IDLE and the
Python shell on any computer that you are using. And being able to run these
can be dependent on which version you have chosen for your system as well.
You will need to go through and check on your system which version of
Python is there before proceeding and then moves on from there to determine
which IDLE and shell you need to work with.
We write a line of codes in Python, starting with the very famous phrase in
Python for every beginner "Hello World" and we will do it in the following
way:
The syntax is written as follows:
print(“\tHi there”)
output:
Hi there #tabbed to the right
There is no space between the text and the escape character \thiya
Here are some of the most regularly used escape characters in Python.
Escape Description
character New Line
\n Horizontal
\t Tab
\\ Backslash
\’ Single quote
\” Double Quote
Let’s have a look at the some more escape characters.
The following sentences would result in an error when printed:
In the first example Python thinks that the inverted comma before hello is the
end of the string. The third inverted comma would cause the program to
crash. Likewise, in the second sentence Python would take the back quote on
the word he’d to mean the end of the string and throw an error when it
encounters the third comma. One solution is to use single quotes when you
intend using inverted commas in the string:
And use double quote if you intend using a lot of back quotes such as he’d,
there’s etc. in your string:
print ( " He said he’d be there at 2pm but there’s no sign of him")
Now what if you want just to print a backslash \ in Python? Yes, you also
must escape it.
So how does this work in real life? Have a look at a snippet from a sample
food menu:
“Available drinks include tea\coffee\water”
To print this in we need to include the escape character \