loading

Programming is awesome!

It's creative, its fun and its gives your brain a mental workout. Many of us want to learn about about programming but convince ourselves that we can't, maybe its has too much math, maybe the jargon thats thrown around scares you. Let me tell you now that that is exactly what ever programmer thought before they became programmers. In fact that's exactly what I though less than 10 weeks ago when I started programming.

Let me tell you right now that anyone can learn to write programs. With advances in easy to read programming languages like python, and the wealth of information on the internet, Its no longer a full time investment to learn the ins and outs of a programming language. Infant most '21st century' programmers are extremely lazy, just learn the basics and build on from there.

This is a No-Jargon, easy to follow ible that you can do right now. Thats right! Minimise facebook and youtube, relax and follow along on your computer.

Old Person Computer

Today we will be looking at a programming language called Python, wikipedia defines python as:

"Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasises code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C++ or Java. The language provides constructs intended to enable clear programs on both a small and large scale."

So what does IT ALL MEAN? I thought you said no-jargon? Well basically:

"Python is a compact, general purpose, easy to read programming language. It is very versatile, so can be used to create programs of all shapes sizes."

Why did I pick python? Because the basics of python are easy to pickup and the language has an excellent support community online. After finishing this ible you can start making programs immediately, instead of spending the your time learning the required intricacies of the language.

So lets start!

Step 1: What You Will Need

Firstly you will need a computer with a copy of python, sorry mobile users!

Head over to https://www.python.org/downloads/ and download the latest release available with the big yellow button.

Python Download

Then follow the Installer Instructions to install python. Python Installer

To verify python is installed, go to CMD (or terminal) and type:

python --version

Python should respond with the version of python.

Now for this tutorial we will be using an IDE, or Integrated Development Environment (basically a text editor and compiler stuffed together) so head over to https://www.jetbrains.com/pycharm/download/ and download the "Community Edition" of Pycharm.

PyCharm Community

Then follow the Installer Instructions to install PyCharm.

Now, to start programming!

Step 2: Setup PyCharm and Create a New Project

The first time you launch pycharm it will ask you what keymap and theme you want to use. I would reccomend leaving the key map at default, but you can play around with the theme, colours and fonts to your liking. For this tutorial I am using pycharm community 4.5 with the Dracula theme.

PyCharm Setup

You will then be greeted with a welcome screen.

Press Create New Project

PyCharm Welcome Screen

Select Pure Python then choose a folder to store the files in, then press create ( Note that the folder name will be the name of your project )

PyCharm Project Screen

At this point you should be greeted with the actual Code Creating Screen :P

Code Screen

Step 3: Create Your First Program

Right Click on your project folder and go to new -> Python File

Create New MENU

Name the file and press ok

File Dialogue

Now a new tab will appear in your main area

Below __author__ copy and paste this code.

message = "Hello World"
print message

Then right click on the file and press Run

This will compile our program and return a result. Hello World will be printed in the Run Area

Lets look at what we just wrote.

Step 4: Figuring Out Your First Program

Now lets try to understand what the code

message = "Hello World"
print message

really means.

Firstly I create and set the value of the variable to a string containing Hello World, If you change the text between the speech marks then you can change the value of the variable and therefore the message. For Instance:

message = "Hello Instructables!"<br>print message

Returns:

when run

A string is defined because of the speech marks, strings can also be defined with single marks

message = 'Hello World'
print message

Variables can also have different types. For Instance this:

integer = 29302

is a variable with an integer value ( abbreviated int ) and this:

floatingPoint = 1469.928

is a variable with a floating point value (abbreviated to float).

Basically, the difference between integers and floats is integers are whole numbers while floats are decimal numbers. Integers take up less room but cannot hold decimals. For instance interger 1 / integer 2

integer1 = 1
integer2 = 2
print integer1 / integer2

is 0.5 right? But the result is:

Because integers cannot be divided into decimals. However this:

float1 = 1.0
integer2 = 2
print float1 / integer2

returns 0.5 when run because one of the variables is a float

'Print' simply prints a value. For Instance

print "DESTROY THE WORLD"

prints the string

Print can also print the value of an equation, including combining two strings

string1 = "HELLO "
string2 = "IBLE LOVERS"
print string1 + string2

prints

Step 5: Loops and If's - Control Structures

One of the most essential things about any program is the existence of control structures.

The first control structure is a while loop, this piece of code loops while a condition is true. For Instance this code

count = 0
while count < 10:
    # Add to count
    count = count + 1

    print count 

print "Finished"

runs the code in the loop until count < 10 and then continues on with the program.

The Second is an if-else statement, this piece of code checks and does something if the value of a variable is equal to 10, does something else if the value is equal to 11 and does something else in all other circumstances.

integer = 0

# If its equal to 10
if integer == 10:
    print "ITS 10"

# If its equal to 11
elif integer == 11:
    print "ITS 11"

# In all other Circumstances
else:
    print "I DONT KNOWWWWWWWW"

print "Finished"

Will return

Because the variable integer is not equal to 10 or 11 and in every other situation it runs else.

To define a while or if control structure put the type (while or if) followed by the true or false value then :

type true == true:

Notice the 'whitespace' for the contents of each loop, python is very specific about whitespace, thats how it knows what code is in a while or if loop. PyCharm uses one tab whitespace which must be consistent across all of you control structures.

Step 6: Comments

You may have noticed that I have 'commented' on the code I posted on the control structures part. You can comment a piece of code by placing a # and the rest of the line will be commented. When the software is compiled the comments are ignored

# Hello World

Comments are the saviour of code. Because they allow you to show everyone whats in your code and what you were thinking when writing the code. But don't overdo it! Over commented code can be just as bad as under-commented code

So when should I comment my code

My rule of thumb is to comment your thoughts as your writing, so if you added a variable just to hold your age that serves no other purpose. Comment that.

<p># Completely Pointless Variable that holds<br># my age in years
myAge = 23</p>

Step 7: Your Finished - Time to Write Something Yourself!

Woah, you just learnt the basics of python!

So what do I do now you might ask, well you can continue to have a play around with your file. When you think you are ready you can take on a challenge. Write a program to add or subtract two user inputted numbers. Use the internet to find out how to get user input then add or subtract the two inputs and be sure to comment your code! Post your code below for suggestions and improvements. Good Luck!

<p>Thank you for this amazing tutorial! </p>
<p>Thankyou for reading and enjoying this tutorial, as well as dropping a comment :)</p>
<p>So there's a question. Why 2.7? Why not 3.5.0 ? I myself using older version, but I've never find good explanation to this question.</p>
<p>I would actually recommend using Python 3.0. But I am currently stuck to using some python 2.7 Libraries and thus I am still using 2.7. When I am finished I will probably make the jump to 3 :P</p>
<p>Nice tutorial but the lack of proper syntax in your demo code will turn newbies off</p>
<p>Hi and tnx for this tutorial. I am using JetBrains PyCharm Educational Edition 1.0 w/ Python 2.7 and 3.4 on my machine. How come when I try to run your 'HelloWorldProgram' I get an 'invalid syntax' error? It only works when I put brackets around 'message'? Am I missing something? </p>
<p>Is it possible to make a website like Instructables with python? </p>
<p>Well theoretically yes, but I wouldn't recommend it. I would learn HTML and CSS as that is what instructibles will be coded in. HTML is the 'base' which contains the raw text and data. While the CSS literally just styles it to look nice. </p><p>You could build applets that run within the website to do certain tasks in python. But you would create a website in HTML and CSS ( Or PHP but thats another story ).</p><p>If your interested in learning how to code websites a good places to start is <a href="http://www.w3schools.com/html/default.asp">w3schools</a>. It has some good info to get you started :P</p>
<p>I recommend ruby as well. Personally I don't like it (That's another story), but as far as I know it's easier to learn than C# or JAVA and still better than PHP (PHP code can be a mess if You don't know how to keep your code clean). Also there's a lot of good sources about Ruby on the web. HTML and CSS knowledge is required as well.</p>
<p>i maade it</p>
<p>Post your code so we can all have a look at it, Suggest additions etc :) </p>
This was awesome!<br><br>I learned Basic and Pascal in high school in the mid-late 80's. <br><br>This seems SO much easier.<br><br>Thank you!
haha, yeah I have heard the stories of 6000 page books containing every aspect of the syntax for a language :)<br><br>Python is pretty awesome, a lot of fun when you get into it. Nice and easy to code with too :P<br><br>Thanks :)

About This Instructable

12,102views

268favorites

License:

Bio: I'm a tech guy at heart, I probably won't be making a skyscraper in my next ible, but I specialise in doing the ... More »
More by EvolvedAwesome:Get Started with Python Get 1 Million Views - By Cheating Achieve the 3 elusive Achievements 
Add instructable to: