ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

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 writer who loves writing articles and tutorials to help you out!

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

working

This website uses cookies

As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://corp.maven.io/privacy-policy

Show Details
Necessary
HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
LoginThis is necessary to sign in to the HubPages Service.
Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
AkismetThis is used to detect comment spam. (Privacy Policy)
HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
Features
Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
MavenThis supports the Maven widget and search functionality. (Privacy Policy)
Marketing
Google AdSenseThis is an ad network. (Privacy Policy)
Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
Index ExchangeThis is an ad network. (Privacy Policy)
SovrnThis is an ad network. (Privacy Policy)
Facebook AdsThis is an ad network. (Privacy Policy)
Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
AppNexusThis is an ad network. (Privacy Policy)
OpenxThis is an ad network. (Privacy Policy)
Rubicon ProjectThis is an ad network. (Privacy Policy)
TripleLiftThis is an ad network. (Privacy Policy)
Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
Statistics
Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
ClickscoThis is a data management platform studying reader behavior (Privacy Policy)