Skip to content

Intro and Installation

Introduction to Python

Developed in 1990s, Python is one of the most popular high-level, interpreted, general-purpose programming languages.

The language almost is similar to plain English, making it easy to write complex code. Since it doesn’t have much of a learning curve, Python is considered a very good entry point for beginners.

Dictionary

General Purpose : can be used for a wide variety of development tasks.

Think JavaScript, HTML/CSS for web development. Python can be used for,

  • Web Applications
  • Data Science
  • Image Processing
  • Scientific and Numeric Computing
  • Cybersecurity

Dictionary

High Level : A high-level language cannot be understood directly by the machine. There is a certain degree of abstraction in the syntax.

Machines are generally designed to read machine code(binary code i.e. 0s and 1s), but the high-level syntax cannot be directly converted to machine code.

There are also low-level languages, sometimes referred to as machine languages or assembly languages.

Two kinds of programs process high-level languages into low-level languages:

  • interpreters
    • An interpreter reads a high-level program and executes it.
    • During execution, each line is interpreted to the machine language on the go.
  • compilers
    • A compiler reads the program(source code) and translates it completely to object code or the executable before the program starts running.
    • Once a program is compiled, you can execute it repeatedly without further translation.

Python is considered an interpreted language because Python programs are executed by an interpreter. As a result, Python code is first converted to an intermediate form called bytecodes which is then converted to machine code(Python does it for us behind the scenes) before the program can be executed.

There are two ways to use the interpreter:

  • command-line mode
  • script mode

Installing Python

You can use the below links to install Python on your machine,

For IDE you can install,

Each python file is stored in <name>.py format. To execute the file we have to open a terminal and execute python <name>.py.

Writing our First Code

The print statement

We will start with age-old tradition by displaying the text "Hello World" on screen.

1
print("Hello World")
Result
1
Hello World

Let's print few numbers.

1
2
3
print(100)
print(2.2131)
print(-22.11)
Result
1
2
3
100
2.2131
-22.11

By default, each print statement prints text in a new line.

We can also print multiple things in a single line using , as a separator in the print command.

1
print(100, 2.2131, -22.11, "Hello Professor")
Result
1
100 2.2131 -22.11 Hello Professor

Comments

A piece of text is used to describe what is happening in the source code.

This is useful for readers so that they can easily understand what the program is doing. These comments have no effects on the execution of code.

We can use # to comment a single line. Anything after the # symbol is considered as a comment in that line.

1
2
3
4
5
6
7
8
print(100)

# this complete line has been commented

# for multiple lines,
print("ola amigo!")
# we can use the hash symbol
# each time
Result
1
2
100
ola amigo!

Alternatively, to comment out multiple lines we can use docstrings.

1
2
3
4
5
'''
    These triple quotes can be used
    to comment out longer notes
    or text about the code.
'''

In the next section, we will start with Data Types and Variables.

Back to top