ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming»
  • Programming Languages

Learn To Program: How To Install Python and Write Your First Progam

Updated on December 31, 2013
susi10 profile image

Susan is a science geek, and if that wasn't enough, she gets all nerdy over technology too. She is also a writer too.

Learning to code brings loads of benefits such as making your own applications for others to use!
Learning to code brings loads of benefits such as making your own applications for others to use! | Source

Learn To Code Tutorials

This is the first of a series of tutorials designed to help you learn the basics of Python.

Learn To Code This 2014

If you want to learn how to program and create programs confidently, then this is the hub for you!

In this hub you will learn:

  1. what programming is
  2. why learn Python
  3. how to install Python
  4. how to write your first program
  5. how to use Python as a calculator
  6. Fundamentals of Python: strings, writing your first program

One of your new year's resolutions may be to learn to code but you don't know how or think it's too hard. That isn't true and this hub will show you how to program.

Source

An Introduction To Programming

What Is Programming?

When browsing the internet, navigating through your folders, made PowerPoint Presentations or typed some text into Word, you have utilised computer programs. These programs run on thousands of lines of code that run and produce the applications you see on your screen. They do not run on magic but run in a logical manner. The intelligent folks at Microsoft wrote those programs for you, they are known as software engineers. It may seem daunting at first, when you think of the complexness of an application such as Microsoft Word but as you write programs, learn more and build confidence you will discover that Microsoft Word runs in a logical fashion, just like all programs. Here are some other facts you should know about programming:

  • Programming is writing code so that a computer can understand it and output the result.
  • You write code and the computer outputs what you asked it to do.
  • You can create word-based programs which are relatively simple to write or graphical programs that make use of
  • Through programming, you can create applications that other users can use on their PC's, tablets and smartphones.

Programming Languages

When you write a program, you are essentially writing code. That code can vary depending on what language you are writing it in. All coding concepts and fundamentals are the same (such as strings, loops, blocks, methods, don't worry you'll learn about it later) but the way you write it is different. Some programming languages are easy to learn than others, whilst some are 'beginner' languages which only serve as an introduction to coding. Here are some languages:

  • Java - I'm sure we have all heard of this one, and it is more than likely to be running on your computer right now. Java is of a moderate difficulty, and you will require a lot of tools (compilers, NetBeans/Eclipse, runtime enviroments etc). I would not recommend this for complete beginners, but you can still have a go at it if you like.
  • C++ - Again, this is a popular language but is fairly difficult for beginners to learn.
  • Python - The language that we will be learning and is slightly easier to learn than Java or C++. It is an official language used by many programmers all over the world and is very easy to set up. I will now explain the advantages of learning Python.



Why Learn Python?

  • It's an easy language to learn, it isn't utter gibberish like some other programs and is easy to understand.
  • Google use it, yep, that's right. They are always looking for programmers in Python so it must be an official language. A lot of Google's products and algorithms were written in Python and if you want a job at Google, you will have an advantage by knowing Python.
  • It is quick and easy to set up. Just one download from Python.org's website and you are good to go. With Java you have to download NetBeans or Eclipse, the JRE, the Java Development Kit and more.
  • It is very easy to run your written code. You simply save your code in Python's editor in any folder you want on your PC and run it.
  • There are so many tutorials out there to help you, from books to websites to courses on Coursera, you can always better yourself if you want.
  • It is always updating and always stays current with today's technology.
  • In a couple of months, you will be able to write games, complex programs and applications with Python.

How To Install Python (Windows)

1. Open another browser window and type www.python.org into the address bar or search for it on Google. Once you have reached Python's homepage, look to the left and you will see a vertically stacked selection bar. Once you have seen this, click on the Download link (see the image below).

2. You will be brought to Python's download page. Then, select Python 3.3.3, the most current and up-to-date version of Python there is.

3. This will bring you to the Python 3 download page and scroll down. If you have Windows, click on the download link which is highlighted in the 3rd picture in the thumbnail below. If you have a Mac, tell me in the comments below and I'll help you out. This download link will download Python to your computer. Make sure it is saved in a place where you will find it, preferably on your Desktop. Open up the Python folder and you will see a variety of folders within it but the actual editor we will be using will be here in the main folder. It is called: IDLE (Python GUI)

4. Open this up and it is time to begin!

Step By Step Process

Click thumbnail to view full-size
1. Navigate to the Download Button on the side of their website.
1. Navigate to the Download Button on the side of their website.
1. Navigate to the Download Button on the side of their website.

Arithmetic In Python Shell

Now that you have Python set up and opened, its time to begin. When you have opened IDLE Python GUI, this is what you'll see, the Python Shell.

The Python Shell is an interactive module where you can input some code and Python will give you the output. You can do arithmetic and basic commands with this, but we won't be using it when coding programs. To begin with though, let's do some arithmethic to get a feel of Python's Shell. Type the following into the Shell and press enter:

5 + 3

Input ->>

And you should get this:

Output ->>

The Python Shell

As you can see, its possible for you to do arithmetic in Python Shell with multiplication, division, subtraction and addition. Not only that but you can also work with big numbers too, a feature that is not available on your calculator.

The >>> is known as a prompt. This means that it is prompting you to write something or waiting for you to give it a command.

With the Shell, you can also print text too. Try typing the following line of code exactly after the prompt and hit enter.

print("Hello World!")

The Text Editor

Well done! You have just gotten your computer to say Hello World! to you. Hello World is usually the first command that beginner programmers ask the computer to do, it has become a tradition. However, it is not a proper program yet, we cannot save it or build on it, it is only a one-line prompt. Instead, we will have to build a program that we can save, reuse and build upon.

To do this, you will need a text editor. In this editor, you can write code, build programs and save these which can be accessed again. Python has a text editor built in. To access it, whilst in Python Shell, go to File and then New Window. This will open up a blank screen waiting for you to fill it up with code. The Shell will give you your output based on the code you've written. It's time to get building!

Writing Your First Program

In your New Window, type the following onto the first line.

Once you have the following typed in exactly, go to File and then Save As. Save your program wherever you want, it does not have to be in your Python Folder. I suggest you create a folder where you can put all your programs. Then, press Run and then Run Module or press F5 as a shortcut. Your program will print Hello World in the Python Shell.

print("Hello World!")

What Your Program Should Look Like

  • The word print means that you want the computer screen to output the text in the brackets to the user, in short, you want text printed on the screen. So, if you want to print text on the screen, use print. You will notice that the word print is highlighted in purple (if you are using Python 3). This is known as syntax highlighting and is one of Python's main features. All functions (or actions that you want your computer to perform) are highlighted in purple. Any words highlighted in purple means that they are keywords, Python recognises them. If you typed printy instead of print, you will notice that it is no longer highlighted in purple. That way you know if you went wrong.
  • After the word print, you have a bracket, then double quotation marks, then your text, your double quotation marks once more and your bracket.
  • You will notice that the text that we wrote is highlighted in green. Python is telling us that it is a piece of text and is a string.

Strings

What is a string? Well, a string is basically a piece of text within a program that will be used in the output of the program. Strings are enclosed in either single quotes or double quotes, and are highlighted in green. You can print any text you like by putting the function print in front of the string. You will be using strings all the time when writing programs so get yourself familiar to them! Other examples of strings include:


print("My name is ...")
print("Its nice to meet you")
print('Hi!')

What do you think of this tutorial?

See results

In The Next Tutorial...

You will be learning about variables, embedding variables in your code. how to create an interactive program where you will communicate with your computer and input.

Click here for Tutorial 2 in Learn To Program With Python.

© 2013 Susan W

Comments

    0 of 8192 characters used
    Post Comment

    • susi10 profile image
      Author

      Susan W 3 years ago from The British Isles, Europe

      Hi Ron!

      Thank you for trying this out and I am glad that you found it useful. Good question! Hmm..that must be very frustrating for you. I would suggest deleting the two Python folders (which are usually downloaded into the Computer OS:C folder on Win7) and re-downloading the 32/64 bit version again. Check what bits your computer (32 or 64 bit) is:

      http://windows.microsoft.com/en-IE/windows7/find-o...

      Here is the exact link for it, make sure you download the version mentioned above.

      http://python.org/download/releases/3.3.4/

      The command line and Python GUI IDLE are both downloaded as part of the package.

      If the problem persists, please let me know and I will try to solve it in more depth (I might send you an email). Or, send a quick email to the Python customer team, they have been helpful to me in the past.

    • RonElFran profile image

      Ronald E. Franklin 3 years ago from Mechanicsburg, PA

      Very good step-by-step tutorial . I had only one problem. After downloading Python as you indicate, when I looked for IDLE in the main Python folder, it wasn't there. Since I'm running Win7, I went back and downloaded the 64-bit version. Same thing. But then I noticed that both "IDLE (Python GUI)" and "Python (command line)" have appeared on my Start menu. So, now I do have the GUI, though it still doesn't show in the folder. I'm not sure if this happens just for Win7. Anyway, I appreciate the intro to Python. Thanks!

    • susi10 profile image
      Author

      Susan W 3 years ago from The British Isles, Europe

      Hi Cyndi!

      Thanks for reading and commenting, I appreciate your visit. I'm glad you liked it...programming can be very beneficial in many ways. I encourage you to give it a go, it might bring you back to the nostalgia of those programming classes in high school! :)

    • cclitgirl profile image

      Cynthia Sageleaf 3 years ago from Western NC

      Well done! I'm impressed because the last time I did any programming was in high school - we used...what was it...Microsoft Quick something...haha. But, I'll have to try this sometime. Thanks for sharing. :)

    • susi10 profile image
      Author

      Susan W 3 years ago from The British Isles, Europe

      Hi James,

      Thanks for the great comment, its nice to get some compliments from a fellow tech expert! Glad you found it useful. You have some great tech hubs too.

    • TOPTENTECH profile image

      James Richton 3 years ago from USA

      Thanks for an easy way to install Python and writing programs. Thanks.

    • susi10 profile image
      Author

      Susan W 3 years ago from The British Isles, Europe

      Hi psychicdog.net,

      Thanks for the read and for the great comment. Interesting question! In Python, you can make databases quite easily. If you like to create a database in Python, try out SQAlchemy ( http://www.sqlalchemy.org/ ) or SQLite. Also, check out the link below which contains links and descriptions for more on databases in Python.

      https://wiki.python.org/moin/DatabaseProgramming/

      Python is a great language to learn and is perfect if you want to learn Java or if you want to make an Android/iOS App. I highly recommend Python but stick with PHP until you have mastered it, if you prefer. I hope this answers your question.

    • psychicdog.net profile image

      psychicdog.net 3 years ago

      Hello Susi - thanks for a good intro ive got deeply into php and don't know if I should start learning python though some very sound sources I have come across have pointed me in this direction. I like the vibes I've been getting around python but is there a regular database used with it? Cheers

    • susi10 profile image
      Author

      Susan W 3 years ago from The British Isles, Europe

      Hi drpennypincher,

      It's nice to see you and thanks for the great comments. When I began learning to code in Python, I did not know which version to download as there was so many different types (bzipped source tarball etc ... where do they get those names?) but after a bit of research I chose the correct one. That is why I incorporated that into this hub as readers might not understand which to download and where to go.

      Thanks for your feedback on this tutorial, at least I know that I am doing it right. :) I was afraid this tutorial would be either too easy or too difficult for beginners but after your great comments, at least I know that you are finding it useful.

    • drpennypincher profile image

      Dr Penny Pincher 3 years ago from Iowa, USA

      Susi10- Thanks for the great Python tuitorial! I like how you start with how to download Python. I was able to download Python and write my first program in about 10 minutes following the steps in your article. I see that you have written Tuitorial 2- that is my next stop.

    • susi10 profile image
      Author

      Susan W 3 years ago from The British Isles, Europe

      Hi rasta,

      Nice to see you and thanks for commenting. I am glad that you will be following this series, I hope that you will learn a lot from this series. I'll be publishing my next tutorial in the coming day or so.

    • susi10 profile image
      Author

      Susan W 3 years ago from The British Isles, Europe

      Hi electronician,

      Thanks so much for reading this and sharing. Yes, Python is a very user-friendly language. Looking at an advanced program, a beginner can still understand the code. Python teaches all the fundamentals you need for other languages such as Java. XML is so much more difficult than Python (I'm trying to get my head around it right now, I'm writing an Android App).

    • rasta1 profile image

      Marvin Parke 3 years ago from Jamaica

      I do some PhP. Looking to master that before taking on any more language. I am definitely moving up to Python as my ultimate language in the future. So, I will be following your series.

    • electronician profile image

      Dean Walsh 3 years ago from Birmingham, England

      Great introduction to Python, which itself is a very user-friendly language which is ideal for beginners. Voted up and shared.

    • susi10 profile image
      Author

      Susan W 3 years ago from The British Isles, Europe

      Hey josters!

      Nice to see you, Janik, thanks for dropping by and for your comments. Yes, I agree Python is a very good programming language to begin with, I suppose if Google use it, it must be good!

    • susi10 profile image
      Author

      Susan W 3 years ago from The British Isles, Europe

      Hi Space Shanty!

      It's nice to see you again, I am very happy when reading your great comments so thank you very much! I hope this hub has helped you to begin coding, and thanks again!

    • josters profile image

      Janik D 3 years ago from Dresden, Germany

      Python is a great programming language. Understanding it also helps you using and understanding Blender much better.

    • SpaceShanty profile image

      SpaceShanty 3 years ago from United Kingdom

      I was just thinking about learning some code recently and then your Hub pops up, you definatly have one regular reader!