Python Programming Language

For coding purpose we will be using Python 3. 

It is a very powerful programming language with very cool features and easy to understand and read syntax. It uses an interpreter that is the code is compiled and executed line by line.


I'll familiarise you with some basic syntax of the programming language to get started with, later we'll go deeper if needed.


Installation:

I would suggest working on Linux rather than windows as it comes pre installed with python and path variables are set.

For Windows:

You need to download and install Python 3.x (currently 3.6.1) from this link: https://www.python.org/downloads/

Once the installation is done, you need to set the PATH environment variable with location where you installed Python. Refer the link below for the same: 

http://pythoncentral.io/add-python-to-path-python-is-not-recognized-as-an-internal-or-external-command/

Online Editor:

If you don't want to bother installing Python on your PC you may use any online editor for running the code: https://repl.it/languages/python3

Executing Code:

You can save a file with (.py) extension and run it on 'cmd' or 'terminal' using the command:

cmd> python path/to/your/file/name.py

I would recommend using Python IDE such as PyCharm for writing code. Its installation is easy and it makes writing the code easy and fast. Download link: https://www.jetbrains.com/pycharm/ 

Syntax:

1. Variables:

Variables in python do not have a data type or in other words variables have a dynamic data type.
Example:
# integer
a = 2

# string
a = '3 Algorithms per week'

# float or double
a = 3.14

2. Printing a text:

Example: 
print("hello world")
or 
print('hello world')

3. Arrays or List:

Example:
# Empty List
arr = [] 

# List with 5 elements
arr = [1, 2, 3, 4, 5] 

# List with different data type elements
arr = [1, 'abc', 2.5, 'c']

# List initialised with 10 1's:
arr = [1] * 10 # Equals arr = [1,1,1,1,1,1,1,1,1,1]
 
# Accessing list elements
print(arr[1]) # Outputs: abc

print(arr[0:3]) # Outputs: [1, 'abc', 2.5]

print(arr[-1]) # Outputs: c

4. Taking input from user:

Example:
# Default input()'s return datatype is string
name = input("Input your name:")

# integers, floats and other datatypes need to be type casted 
age  = int(input("Enter your age:"))

print("Alternate way for input msg:")
age = int(input())

These basics will help you understand the code I provide in future posts.
I'll also put the links for code in other programming languages.

Useful links:

To learn more about python programming language and its syntax: http://www.geeksforgeeks.org/python/

Post in comments below for any doubts. 

Cheers,
Anubhav Shrimal

Comments

  1. Replies
    1. Hi, I gave an overview about python so that the readers are able to understand the code I provide. The algorithms I'll write will be in layman language so no need to worry if you're not comfortable with Python.
      That being said Python is a great programming language with an easy to understand syntax its not as verbose as Java. More over python is one of the most widely used programming language in current scenario in industry.

      Delete

Post a Comment

Popular posts from this blog

Segregate Even Odd value nodes in a linked list

Tree data structure

Reverse alternate k nodes in a linked list