Python – First Step

We will learn here how to write and run python programs. Before you start, you should have Python installed on your computer.

Install Python and IDLE

Python comes pre-installed with Ubuntu and Mac OS, but it does not come pre-installed with the Windows operating system. You need to download and install manually from the official website of python https://www.python.org/downloads/. and install it in very simple steps.

IDLE: Python IDLE (Integrated development and learning environment ) is an integrated environment for python programming. IDLE is a simple IDE and suitable for beginners and an educational environment. For window users, it is a part of the python software, you need not install it separately. For Linux user, run below command in Terminal.

sudo apt-get install python3 idle3.

Python Version Check

Run below command from terminal or cmd to check python installed on your PC and version of python.

python --version

Working in Python.

Now python is installed in your PC, and you are ready to work with python environment. You can work in Python in two different ways.

  • Interactive mode
  • Script mode

Interactive mode – In interactive mode, you can run python command and you can use python as a calculator. You can execute one command at a time only, after every execution it produces the result.

Script mode – Here you can write multiple lines of code as a file with a .py extension and execute the file as a python program. We will discuss the python scripting mode in the next chapter.

Python as a Calculator

We can use Python as a calculator. to use python as a calculator we will use the interactive mode of python.

For Interactive mode, you need to open Python IDLE from start menu in Window: Start -> Program -> Search IDLE

Mac or Ubuntu: Type IDLE3 in your terminal window.

The above command will open the Python shell, you can write any complex calculation.

Python 3.4.3 (default, Nov 12 2018, 22:20:49) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

You can see the symbol (>>>), where you can write calculation, python will print result.

Some More Examples

>>> 12+12
24
>>> 12+12*12
156
>>> (12+12)*12
288

Arithmetic Operators

>>> 10+3	# Print Addition
13
>>> 10-3	# Print Subtraction
7
>>> 10*3	# Print Multiplication
30
>>> 10/3	# Floating Divison
3.3333333333333335
>>> 10//3	# Integer Divison
3
>>> 10%3	# Modulus, Return Remainder
1
>>> 10**3	# Exponent, Cube of 10
1000
63
Created on By S. Shekhar

Python - Quiz 2

1 / 1

IDLE stands for

Your score is

The average score is 67%

0%