Thanks to theidioms.com

Learn Python For Data Science (Course I)

Learn Python For Data Science (Course I)

Installing Python and Getting Started

Your first Python programming lesson is here and in this chapter, you will learn how to install Python on your operating system. This may not sound like fun but the fruit of this lesson will be sweet, i.e., you will be able to write your first line of Python code once you’re done installing.

Unlike other popular programming languages (such as C and C++), Python uses an interpreter which is just a computer program that directly executes written instructions. This also means that all scripts written in Python are executed line by line and not all at once.

Installing Python on Windows

The Python interpreter can be installed on Windows by following these instructions:

1. Download the latest stable build of Python from the following link: https://www.python.org/downloads.

Download Python Installer from Python's Website

2. Once the installer has been downloaded, run it. Make sure to check ‘Add Python 3.8 to PATH’ and press on ‘Install now’.

Run Python Installer

Once the installation finishes, you are ready to use Python!

Installing Python on other operating systems

If you are currently on Linux, Mac OS or any other operating system (other than Windows) please follow the guides given by the Python development team:

The installation process includes downloading the appropriate installer for your operating system and running it on your machine. Some OS (eg: Linux, macOS) provides a package manager that can be run to install Python. Moreover, if you are using a mobile phone (eg: Android and iOS), you can install apps that provide a Python programming environment.

Getting Started with Python

Once you have installed Python on your system following the above instructions, it is time for you to check if it is working.

Open command prompt and type python. If a similar kind of interface appears on your prompt then you have successfully installed Python.

Python command executed in command prompt

Note: Your python version may be different from the one shown in the photo as per the latest build available from the Python website.

Let us try writing a simple Hello World program to see the Python interpreter in action.

print("Hello, World!")
Hello, World!
A simple hello world program in Python command prompt

You have successfully wrote your first line of Python code. Now, before we start coding, let us know how to write comments in Python.

Comments in Python

Comments are basically a programmer-readable explanation or annotation in the source code of a computer program and are ignored by compilers and interpreters. Types of comments used in Python are Single-line and Multi-line comments.

1. Single Line Comment – Single line comments in Python begin with a hash mark (#) and whitespace character and continue to the end of the line.

# Example of a Single-line comment: The line below prints “Hello, World!” to console 
>>> print("Hello, World!") 
Hello, World!

2. Multiline comment/Block Comments – Usually, a multiline string can be wrapped as a whole comment inside a set of triple quotes (”’) for block comments.

"""
Example of a Multiline comment:
 The code below takes an input from the user with the message: "Enter your User name:"
 Suppose the user entered "John"
 After user Enters the name it gives out the message: "Hello, John"
"""

# Getting a user input
>>> user_input = input()
John
# Printing the user input
>>> print("Hello, ", user_input)
Hello, John

There you have it! You have installed Python, written your first Python code, and learned about the use of comments. Head onto the next chapter on Data Types and Operations in Python to dive into Python coding in detail.

Close Bitnami banner
Bitnami