Pages

Wednesday, December 9, 2020

Getting Started with Python

Python


Python is an interpreted (not compiled), high level and general purpose programming language. Python supports both Object oriented and Structured programming models.

Python is the world's most popular programming language in 2020. Probably this would continue to be the same for another decade or so.

Before we start on with Python, There are some basic questions that comes to most of our mind.

  • Why should we learn Python?
  • What makes Python different from other Programming Languages? 
  • Why is it so popular? 

Probably it's the same answer for all these questions. Let's see what makes Python so special. 

  • High level programming language with simple syntax and easy to read, write and learn. This would result in Increased Productivity.
  • Python is an interpreted language and executes the code line by line in run time. This makes it easier to analyze and debug in case of any errors. 
  • Python has huge standard library, this makes it easier for development to pick the required function rather than having to develop it. 
  • Dynamically typed, Python automatically assigns the data type to a variable in the run time based on the value being assigned. 
  • Independent of Platform, Python code can run on different Operating Systems like Windows, Mac and Linux.

Getting Started


So, what do we need to get started with python? 

  • Installation
  • Text Editor/IDE

Installation


Some of the computers may already have python installed already. To check the version of python installed, run the below command in Command Line (or Terminal on Mac). 

python

Python

Command 'python' by default look for python2. In the above screenshot, highlighted is the python version installed (Python 2.7.16).

To check if Python 3 is installed, run below command in the terminal. 

python3

Python 3

Python commands can be directly run from the terminal. 

E.g.:

Let's print "Hello World" from terminal. 

print("Hello World, My First Python Statement")


Python Script

Text Editor/IDE:

Program is a set of executable statements and we can't always run them from command line. 

There are various Text Editors and IDEs which are tailored to work with Python script. These would make working with python much easier. 

I prefer to use 'PyCharm' and there are many other IDEs. 

Now, let's create a python script main.py with 'print' statement and run. 

print - python

When we run this script, this prints the text we have provided to print. 

print - python

We have successfully run our first Python script. Happy Learning... 

If you have any suggestions or comments, Please leave a comment or email me using the Contact form.

No comments:

Post a Comment

Exception Handling in Python (try - except-else-finally)

Exception Handling in Python Exception handling is key for any programming language. When an exception occurs Python interpreter stops execu...