Introduction to Modern Python

Introduction to Modern Python

pyth.jpg

Python is an interpreted, high-level programming language created by Guido Van Rossum and released in 1991.

Python language is mainly used in used in web development, game development, data science, artificial intelligence and machine learning.

Python programs have the extension .py and can be run from the command line by typing python filename.py.

Features of Python

  1. Open source: This means that anyone can contribute to Python development
  2. Easy to read and code: Python uses simple syntax which makes it easily understood by developers
  3. Free: Python has no cost of charge.
  4. Robust standard library: It has an extensive library containing functions, modules etc. which is easily accessible thus no need to write code for everything.
  5. Object Oriented Approach: It uses object oriented language concepts such as objects, classes and encapsulation in providing solutions.
  6. Interpreted: The source code is executed line by line, not all at once.
  7. Portable: Python code can be shared and it would work the same way it was intended to in different machines with various operating systems.

Installation of Python

One needs to download the latest version of Python for your operating system here. After doing so, read this tutorial on setting up a python development using VS Code and implement it.

Creating your first Python program

You need to first initialize VS code and create a new folder called Hello. Here create a new python file: hworld.py file and enter the following code and save the file:

 print("Hello world")

To execute the hworld.py file, run it in the IDE giving the following output:

   Hello World!

Another way to execute the file is by launching the Command Prompt on Windows or Terminal on macOS or Linux.

Then, navigate to the Hello folder file, and typing the following command to execute the hworld.py file:

python hworld.py

Returning the result:

Hello World!

Indentation

These are spaces at the beginning of a code line used to show a block of code.

if 34 > 28:
   print("Thirty four is greater than twenty eight")  
if 67 < 94:
   print("Sixty seven is less than ninety four")

Note that:

  • Python 3 doesn't allow mixing tabs and spaces for indentation.
  • Be careful and consistent throughout your code when indenting to avoid unnecessary syntax errors.

Variables

These are containers for storing data. They are created upon assigning a value to a variable. Python has no command for declaring a variable.

full_name = "Hashnode"
print(full_name)

number = "10"
print(number)

Comments

Comments help in providing clear and precise explanation of a particular python code. Python comment starts with the # symbol.

# This is a single line comment

#This is an example of a  multi-line comment 
   #it does not stop
   #after the first line

This is a first of my blog series in Python Programming which is updated weekly. Happy learning!