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! In this chapter, you will be installing Python on your operating system. This may not sound like fun, but the fruit of this lesson will be sweet, that is, you will be able to write your first line of Python code. 😊

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

It is quite rare that a Windows operating system comes pre-installed with Python. However, installing it by yourself is pretty simple and quick.

All you have to do is download an executable installation file from Python’s official website and run it on your system. However, do make sure that you download the latest stable build of the Python interpreter.

Follow these instructions for installing Python interpreter on Windows:

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

installing Python

2. Once the installer has been downloaded, run it. Make sure to select ‘Add Python 3.8 to PATH’ and press on ‘Install now’. If your downloaded Python version is different from Python 3.8 then the version name on the option will be different.

Run Python Installer

The installation time can take anywhere from 30 seconds to 2 minutes. 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) follow the steps in Python documentation:

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

Getting Started with Python

After installing Python on your system, it is time for you to check if it is working.

Open Command Prompt and type python. If you see a similar kind of message in your Command Prompt window, 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 image, depending on the version that you installed 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 written your first line of Python code. Now, before we start coding, let us tell you how to write comments in Python.

Comments

Comments are programmer-readable notes or annotations in the source code of a computer program and are ignored by compilers and interpreters. You can write single-line and multi-line comments in Python.

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

# Example of a Single-line comment: The line below prints “Hello, World!” to the 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 (”’).

"""
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 the user enters the name, it returns out the message: "Hello, John"
"""

# Getting 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 learnt about the use of comments. Head onto the next chapter on Data Types and Operations in Python to deep dive into detailed Python coding.

Close Bitnami banner
Bitnami