Day-3 || Python2 vs Python3 ||

Python

Day-3 || Python2 vs Python3 ||

Hello world!! Welcome to my Python course, In this course i will take you from the absolute basic concepts to Advanced concepts like web development framework and libraries for machine learning.

Welcome to Day-3 of my python course, Hope you loved my day-2, I know day-2 is very boring with installations and all those stuff. Today we will go into basic python coding and differences between Python 2 and Python 3.

For this course we will use an online Jupyter notebook access this notebook here,

http://jupyter.org/try

Click on the above link and you will a selection bar where you need to select python.

When you click on Python it will create a new repository where you can store your programs

Python is a scripting language and uses interpreter but not compiler so it will check line by line and gives you the error . Jupyter allows you to run the code like modules.

Hello world programs:

*We don’t need to add semi colon at end of each line.

*We don’t need to use curly braces.

*No need to give datatype for variables explicitly.

Program-1:

1.a=10

2.b=20

3.c=a+b

4.c

output: 30

Program-2:

1.print(“Welcome to cs open source”)

output: Welcome to cs open source

Python2 vs Python3:

So executing Python programs is this easy, Now we have a basic python structure so we will discuss about differences between Python 2 and Python 3.

As we discussed in Day-2 we are going to talk about four major differences,

1.Print function:

Python2:

print 'welcome to csopensource'

Python3:

print('Welcome to csopensource')

Print function got a braces in python3 but not in python2. If we write print function with braces in Python2 it will give you a syntax error.

2.Range and Xrange

These functions do the same functionality of specifying the range,

python2:

for x in xrange(1, 5):
    print(x),

python3:

for x in range(1, 5):
    print(x),
3.Error Handling:
 There is a small change in error handling in python3, Python 3 needs as keyword.
Python2:
try:
    trying_to_check_error
except NameError, err:
    print err,
Python3:
try:
     trying_to_check_error
exceptNameError as err:
     print(err, 'Error Caused')

_Future_ module:

This is a great function which is used to migrate from one python version to other.

from__future__ import Your module

The terms, Blocks and everything used above will be discussed in the later articles.

Here the conclusion is Python 3 and Python2 both were given same importance and Python 3 is little bit advanced and there are some projects and frameworks work only on Python2 but not python3

How to run both the versions in one machine:

Advanced basic concepts in Python::

Here we discuss the advanced basic concepts and then jump into core python.

1.Python can be used for both scripting and general programming.

2.Python is a simple,High level and object oriented language.

3.Python is interpreted language.

4.Python is a open source language.

5.Python is an expressive language.

6.Python is a cross platform language.

and this list goes on,

So, Now we completed our basic python part of installation and writing basic programs. We will jump into programming modules now.

This is the end of Python day-3, Hope you loved it, Do share this with your friends if you think it’s useful, Please give your feedback [at] naveen.csopensource@gmail.com

Can’t wait to see you in the day-4 of this course.

Video Tutorials for this course will be coming soon, All the resources will be sent to your email everyday and projects will be uploaded into GitHub.

 

 

 

 

 

Naveen Surampally

Hello, world !! Naveen here, Founder of csopensource and I am a constant believer that information should be opensourced and accessible to everyone. Here in this blog, you will get all kind of stuff for free.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.