Python Introduction – Free Python Tutorials and online Training

What is Python ?

Python is a HIGH-LEVEL, GENERAL PURPOSE, OBJECT-ORIENTED and STRUCTURED programming language, with applications in numerous areas, including web programming, scripting, scientific computing, robotics, and artificial intelligence. It is very popular and used by organizations such as Google, NASA, CIA, and Disney.


History of Python:

Guido van Rossum developed the language Python and it was first released in 1991. Guido van Rossum (born 31 January 1956) is a Dutch programmer best known as the author of the Python programming language, for which he is the “Benevolent Dictator For Life” (BDFL), which means he continues to oversee Python development, making decisions when necessary. Python is famously named not after the constrictor snake but rather the British comedy troupe Monty Python’s Flying Circus.


Features of Python:

Python language has many features:

  • The Python codes are very small and easy to understand compared to other languages. As an example, say we have to print “Hello World” to the screen. We just have to write ‘print(“Hello World”)’ in the Python console. That means to print a statement we have to write just only one line of code in Python, whereas in other languages like JAVA to print only “Hello World” we have to write seven line of code, in C language we have to write four line of code to print only “Hello World”. So obviously Python codes are small and simple.
  • Python codes are processed at runtime by the ‘interpreter’. We don’t need to compile our program before executing it. An Interpreter is a program that runs scripts written in an interpreted language (as Python). Just we have to write our python code and run the program in the python shell.
  • In Python, whitespace indentation is used rather than curly braces. That means in Python, to write a block of code we don’t have to use curly braces, we need to provide proper whitespace indentation in-place of that curly braces.
  • In Python, while declaring a variable we don’t have to provide the data type for that variable. Python will automatically typecast the variable according to the data we assign to it. As an example, in Python ‘int a=10’ will give us an error. We have to write ‘a=10’ only. Whenever we reassign a new value to a variable, the variable will be typecasted again automatically according to the new value.

We will talk about more features of Python later.


A sample program in Python:

We need to keep some points in mind:

  • Every example here are made with Python version 3, the syntaxes will be different for Python version 2(not in every case, but for some cases).
  • In the codes, at the end of every line, we don’t need to place ‘;’, it is not mandatory in Python. It doesn’t matter if there is a’;’ or not at the end of the line.
  • in Python for commenting a line ‘#’ is used. If we place ‘#’ in front of a line in any Python code, that line will not be executed.

Example -1:

# Printing 'Hello World'
print("Hello World")
# The above code will print 'Hello World' on the screen

When we will execute the above python program we will get the below output

>>>Hello World

Example -2:

# Let's create five variables i,s,f,c,b with 
# integer, String, float, char and boolean values respectively

i=10
s="Rajesh"
f=10.5
c='R'
b=True

# Now let's print their values

print(i)
print(s)
print(f)
print(c)
print(b)
# That was a kind of way to declare variables

# We can declare variables also in the way shown below

i,s,f,c,b=10,"Rajesh",10.5,'R',True

#Now let's print their values

print(i)
print(s)
print(f)
print(c)
print(b)

Now if we run the above code we will get the output as:

# For first print statements

>>>10
Rajesh
10.5
c
True

# For the second print statements

>>>10
Rajesh
10.5
c
True

Example – 3:

To get input from user we use ‘input’ command. Here we have to keep one thing in mind, by default every input from user is stored as a String value, so we need to typecast the input as per our requirement:

# We take user input using input command

a = input("Enter a value : ")

# The message given within the paranthesis with input command
# will be printed on the screen while taking input.

# when we execute this line the output will be as:

# >>>Enter a value : _

# '_' represents that the cursor will blink at that posotion
# Now if we print the variable 'a' we can see the user input on the screen

print(a)

The output will be as:

# Assume we have geiven 5 as input

>>>Enter a value : 5
>>>5

# In this case the value 5 is stored in variable a as a string, not an integer

Example – 4:

# As discussed earlier python uses whitespace indentation not curly braces
# So let's take an example of the if-else block

a = int(input("Enter an integer value : "))

# Input value will be stored in 'a' as an integer value as we have typecasted

if(a%2==0):
    print("Value is even")
else:
    print("Value is odd")

# After every conditional or loop statement there must be a ':' as we have given
# after the if statement
# Entire block of code under every condition or loop will have proper 
# whitespace indentation

When we execute the code we will get the following output:

# Assume we have run the code two times, the first time we have given input 5
# and second time we have given input 4

# Output for the first case

>>>Enter an integer value : 5
Value is odd

# Output for the second case

>>>Enter an integer value : 4
Value is even

Hope this introductory tutorial will help you in your need. Thank you.

Leave a Comment

Your email address will not be published. Required fields are marked *