Employment News E-Paper(19th June 2021 to 25th June 2021) Click Here

Python

 Learn Python 

Welcome to

Let's Learn Python!

    Here you'll find step-by-step instructions for getting started with the  Python programming language.

Just click on Learn to begin.

Hi there, and welcome to "Let's Learn Python"!

    This online tutorial was written with kids in mind — it's based on the curriculum from the beginner Python class that's been taught at the annual PyCon North America conference since 2012.

    But any beginning programmer at any age could enjoy this curriculum and learn from it.

    Python is used by some of the world's biggest technology companies and websites. Lots of people use Python to make games. You can also use it to make maps. A lot of people use Python to help them with scientific research. It's used to manage images and animation in movies. I even met someone once who used Python to write tools that calculate the structure of airplane wings and figure out how much stress they can handle.

    So the possibilities are pretty much endless. Almost anything you can think of to do with computers, you can do with Python.

Ready to get started?

Let's go!

Lesson 1: Getting Started Lesson 2: IntroductionLesson 3: MathLesson 4: StringsLesson 5: VariablesLesson 6: ErrorsLesson 7: BooleansLesson 8: ListsLesson 9: LogicLesson 10: LoopsLesson 11: FunctionsLesson 12: InputLesson 13: ModulesLesson 14: GamesLesson 15: MinecraftLesson 16: Wrapping Up

Click Lesson 1 to begin.

Lesson 01:

Setting Up Your Raspberry Pi

We really recommend using a Raspberry Pi for this tutorial! It's a great platform for beginners. It's inexpensive, simple to assemble, and best of all you won't need to worry about installing anything since all the tools you'll need - including Python itself - are already there.

If you're using a Raspberry Pi for the lessons on this site and you're starting from scratch, here's what you'll need to set it up.

Raspberry Pi is a credit-card-sized computer, simple enough to assemble in just a few minutes and powerful enough to run many applications.

Along with the Raspberry Pi itself, you'll need a few other small pieces of equipment. These days, it's easy to get most of the things you need in a kit, such as this one. For more options, go onto Amazon or your favorite electronics website and search for 'raspberry pi starter kit'.

Equipment you should have:

  • Raspberry Pi
  • Protective case (optional but recommended)
  • Micro USB power supply
  • A compatible SD card, with NOOBS installed (Most kits include a card that already has the NOOBS operating system installed - if you buy a card independently, you'll have to download NOOBS and install it yourself.)
  • Keyboard and USB connector
  • Mouse and USB connector
  • Monitor and HDMI cable

Most kits will come with a guidebook for assembling all of the pieces to get your Raspberry Pi desktop up and running. The Raspberry Pi website also has a Quick Start Guide that explains all the parts of the computer and walks you through installation.

Once the board is in its case, all the peripherals are hooked up, and the power supply is plugged in, turn on the monitor. You should see an installation screen.

Installation:

  1. If you're prompted to install several options, only check the box for 'Install Raspian'. Do not select any other options
  2. Click the Install icon
  3. If you get a popup asking if you want to overwrite the existing OS, select YES.
  4. Sit back and wait - this step will take a few minutes.
  5. When the installation step finishes you should see an 'OS Installed' message – click 'OK' to continue.
  6. When the desktop comes up, here are some localization changes that you might want to make:
    • Go to Menu > Preferences > Keyboard & Mouse > Keyboard Layout and select the appropriate Country/Variant. For students in the U.S., that will be Country: the United States and Variant: English (US).
    • If you want to change your computer's timezone, go to Menu > Preferences > Raspberry Pi Configuration, click on the Timezone button and select the appropriate country and zone name.

For more help with setting up your Raspberry Pi:

https://www.raspberrypi.org/documentation/setup/

Installing Python

If you're using a Raspberry Pi, you can skip this step - the Raspberry Pi comes with Python already installed.

If you're working on your own computer, here is some information about installing Python for different operating systems.

Apple/MacBook

Versions of Mac OSX going all the way back to MacOS 10.2 (Jaguar) should already have a version of Python installed. However, for this tutorial, you will need a version from the Python 3 series. We recommend downloading and installing Python 3.5.1.

Downloads for Mac OSX can be found here:

http://www.python.org/downloads/mac-osx/

You'll be downloading a package that comes with an installer. Once you run that, you should be able to go into your Applications folder, find the Python 3.5 folder, and double-click to launch Idle.

For more information about installing and running Python on a Mac, see this page:

http://docs.python.org/3/using/mac.html

Windows

Python packages for Windows come with easy graphical installers. To start, download a package from this page. You will need a version from the Python 3 series. We recommend downloading and installing Python 3.5.1:

http://www.python.org/downloads/windows/

For detailed information about running the installer and launching Python on your Windows desktop, please see the documentation on this page:

http://docs.python.org/3/using/windows.html

Linux

If you are using a computer with a Linux desktop, you'll find Python downloads here:

http://www.python.org/downloads/source/

Remember, you will need a version from the Python 3 series. We recommend downloading and installing Python 3.5.1.

For more information about installing Python, see this documentation page:

https://docs.python.org/3/using/unix.html

Other Options

If installing Python just isn't an option, don't despair! There are still a few places online where you can practice with Python.

You won't be able to use these browser-based tools for saving files and creating Games, or for interacting with Minecraft, but you can still use them to type most of the commands from this tutorial.

IdeOne has an in-browser environment that allows you to save several lines of code and run them as a script - you can use this for the exercises in the Games section (be sure to select Python3 when running your code).

The Python interpreter

The Python language comes with a tool called an 'interpreter'. You might also see it referred to as an 'interactive shell'.

Out in the real world we know what an interpreter is - it's a person who translates from one language to another. Well in the computer world, we need a program to translate our Python code into another kind of language that the computer can understand.

In other words, the interpreter lets you interact with your computer using the Python language.

Here you can see an example of what an interpreter might look like:

https://www.python.org/shell/

Once the shell is started, you might notice a few things:

At the very top, you should see the word 'Python' followed by some numbers. Those numbers mean the version of Python that's installed where the shell is running. The version you have installed on your own computer might be a little different, but as long as it starts with a 2 or 3, you should be okay.

The other important thing is the three arrows at the bottom. In some shells, you might see a flashing cursor next to the arrows. In the version on the Python website, we see a red box that indicates where you should start typing.

We call this a 'prompt', and this is the place where you'll type Python code.

Introducing Idle

To learn Python with the exercises on this website, we're going to use an application called IDLE.

IDLE is a program that's also a programming environment. This is where we're going to write our Python code.

IDLE works a lot like a regular Python interpreter, but it has some special features that will make it easier to learn.

Opening IDLE

If you're using a Raspberry Pi, you should see an IDLE icon on your desktop or in your programs menu. Just double-click on that icon to open the program.

If you're using a Mac or Linux computer, you'll need to go to your Applications folder, find the IDLE icon (it should be in a Python folder), and click on it.

If you're using Windows, go to the Start menu, look for Python, and select IDLE.


IDLE looks a lot like the interpreter we just saw on python.org doesn't it? It has some of the same features - a Python version number at the top, and a prompt (in this case, the prompt should look like three arrows, or ">>>").

Remember that when we type something at that prompt and hit Enter, Idle is:

  • translating what we've typed
  • talking to the computer
  • then getting an answer from the computer and sending it back to us in a language that WE can understand