Skip to main content

Introduction to Python

Introduction      

Most of us would be very interested in game designing even before knowing what is it about. We get admired by the way the games we play are designed and that becomes the cause for many of us to have the wish to become a game designer. So this is the platform where I am going to share with everyone what I have learned. When it comes to game designing, everyone knows that there is some serious coding stuff done behind and behind every successful game in the market, there would have been coders and designers working very hard for nearly more than 5 years. So we need to learn  programming languages with great interest to get into
game designing.

Python is a latest language which is more convenient and easy to learn and work with.It is easy to learn it as it has built in capability for many features. We can perform the operations with a single line of code which requires several lines of code to be written in languages like C, C++,etc

Installing Python :

To install python in windows, we must first download the python package suitable for our operating system.
The python software can be downloaded from the official python website. Click here to take you to the Python downloads page.Now that we are in the python downloads page, there are options to download the software for Windows, Linux/Unix and Mac OS. Several versions of the python software are available. In our blog, we use Python-2.7  for running our programs.
The latest version release will be on the top of the download page. To download a specific version release, scroll down. A list of all the versions available will be displayed from which we can select the version to be downloaded.



Clicking on the version you need to download, you will be directed to the next page. Scroll down and click on the Windows MSI Installer ( either 64bit or 32 bit according to your system).
I am going to write the python programs in a windows machine.So let me tell you the instructions how to install python package in windows after downloading it.

After downloading the software package,we need to install it. Just go to the downloaded location and double click on the MSI installer. and click Run. The setup dialog box opens with two options.
If you are the only user on the computer, You can simply select "Install for all users". Or if you have multiple user accounts on your computer  and you need not want the python to be installed across all the accounts, Select "Install just for me" and press Next.
On the next page, select the location of installation or leave it as it is. The default location of installation is C:\Python27\ . Click Next And click Finish to finish the installation.

So, let's get started. Now that we have successfully installed python in our computer system, we can write python code and run in our system.

Python like any other language like C, C++, JAVA has its own syntax . Unlike C, C++ or JAVA, Python does not use flower brackets ({,}) to indicate a segment of code. Instead it uses indentation to identify a block of code.



For example, we will look at our first program; the most favourite one for everyone.

Guess what...
It's the 'hello world' program. Printing hello world on the screen. ;-)

In python, we just need one line of code for this.

                print 'hello world'

We can write the python code in just a notepad and save it with .py extension or we can write programs in IDLE(Python GUI). Open the python idle window. Click on File and select New Window.



There we can write the program and save it with .py extension. IDLE is more user friendly and changes the colour of the text when keywords are typed.It also auto indents the code providing ease of use.

Write this line of code and save it in a desired location,say as 'hello.py'. Now we need to run the program.

Open a command prompt and move to the location where the python file resides.
Now type python hello.py . This will run the code and print the result as "hello world".


                                    
In python, print is a keyword used to print the value given to  the console screen.

We have written our program in python ! Though it is the simplest program, we have started writing a program in python. Now, let us  proceed in this way and enter into the 'World of Python' and explore.

                      >> Next : Python Datatypes and Variables >>



Comments

Popular posts from this blog

Introducing Pygame

Hello Everyone! Let's get into the most interesting topic. We are going to see how we design games using python programming language, Let me introduce you to ' pygame' . Pygame is an open-source and free python library which is used for creating multimedia applications like games built on the top of an excellent SDL library. Pygame is highly portable and can be run on nearly any platform and operating system. First of all,We need to download the pygame library which can be downloaded from the official Pygame  website. Several versions of pygame compatible for the various versions of python are available. We need to select the appropriate version of pygame for our version of python and download and install it. Here i use Python-2.7. So i downloaded pygame-1.9.1 For using pygame library in a python program, like importing any other module, we must import pygame using the command.               import pygame You can also check if you ...

Drawing shapes And Filling colours

Till now, we have written a python program to open a blank black screen and the QUIT event is handled. In this post, let's see how to add colours to the game surface and draw shapes onto the screen. Filling colours : By default, pygame has no predefined colours. We have to define the colours by giving the RGB(red,green,blue) value of the colour.   import pygame pygame.init() white = (255,255,255) black = (0,0,0) red = (255,0,0) green = (0,255,0) blue = (0,0,255) display=pygame.display.set_mode((500,500)) game_loop=False while not game_loop:     for event in pygame.event.get():         if event.type==pygame.QUIT:             game_loop=True     display.fill(blue)     pygame.display.update() pygame.quit() quit() Here i have defined the basic colours by giving the rgb value of those colors. The values are given as a tuple here. Since white is a mixture o...