Lesson 1: Intro And Installation

Lesson 1: Intro And Installation

Learning Path: Python for Programmers, Module 1: Python Fundamentals

Table of Content

This lesson is a part of Learning Path, Python for Programmers.

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.

python-logo.png

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

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.
n1_001.png

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.

print("Hello, World!")
Hello, World!

Let's print few numbers.

print(100)
print(2.2131)
print(-22.11)
100
2.2131
-22.11

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

print(100, 2.2131, -22.11, "Hello Professor")
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.

print(100)

# this complete line has been commented

# for multiple lines,
print('ola')
# we can use the hash symbol
# each time
100
ola

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

"""
    These triple quotes can be used
    to comment out longer notes
    or text about the code.
"""

I'll be sharing the practice problem set as we finish one complete module.

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