Google yields thousands of articles on this topic. Some bloggers opposed and some in favor of 2.7. If you filter your search criteria and look for only recent articles (late 2016 onwards), you would see majority of bloggers are in favor of Python 3.6. See the following reasons to support Python 3.6.
1. The official end date for the Python 2.7 is year 2020. Afterward there would be no support from community. It does not make any sense to learn 2.7 if you learn it today.
2. Python 3.6 supports 95% of top 360 python packages and almost 100% of top packages for data science.
What's new in Python 3.6
It is cleaner and faster. It is a language for the future. It fixed major issues with versions of Python 2 series. Python 3 was first released in year 2008. It has been 9 years releasing robust versions of Python 3 series.
There are several reasons to learn Python. Some of them are as follows -
- Python runs well in automating various steps of a predictive model.
- Python has awesome robust libraries for machine learning, natural language processing, deep learning, big data and artificial Intelligence.
- Python wins over R when it comes to deploying machine learning models in production.
- It can be easily integrated with big data frameworks such as Spark and Hadoop.
- Python has a great online community support.
There are two ways to download and install Python
- Download Anaconda. It comes with Python software along with preinstalled popular libraries.
- Download Python from its official website. You have to manually install libraries.
Recommended : Go for first option and download anaconda. It saves a lot of time in learning and coding Python
- Jupyter (Ipython) Notebook
Spyder - Python Coding Environment
- Press F5 to run the entire script
- Press F9 to run selection or line
- Press Ctrl + 1 to comment / uncomment
- Go to front of function and then press Ctrl + I to see documentation of the function
- Run %reset -f to clean workspace
- Ctrl + Left click on object to see source code
- Ctrl+Enter executes the current cell.
- Shift+Enter executes the current cell and advances the cursor to the next cell
List of arithmetic operators with examples
|+||Addition||10 + 2 = 12|
|–||Subtraction||10 – 2 = 8|
|*||Multiplication||10 * 2 = 20|
|/||Division||10 / 2 = 5.0|
|%||Modulus (Remainder)||10 % 3 = 1|
|**||Power||10 ** 2 = 100|
|//||Floor||17 // 3 = 5|
|(x + (d-1)) // d||Ceiling||(17 +(3-1)) // 3 = 6|
x = 10
y = 3
print("10 divided by 3 is", x/y)
print("remainder after 10 divided by 3 is", x%y)
10 divided by 3 is 3.33
remainder after 10 divided by 3 is 1
x = 100
x > 80 and x <=95
x > 35 or x < 60
x > 80 and x <=95 Out: False
x > 35 or x < 60 Out: True
|Comparison & Logical Operators||Description||Example|
|>||Greater than||5 > 3 returns True|
|/td>||Less than||5 < 3 returns False|
|>=||Greater than or equal to||5 >= 3 returns True|
|<=||Less than or equal to||5 <= 3 return False|
|==||Equal to||5 == 3 returns False|
|!=||Not equal to||5 != 3 returns True|
|and||Check both the conditions||x > 18 and x <=35|
|or||If atleast one condition hold True||x > 35 or x < 60|
|not||Opposite of Condition||not(x>7)|
It is used to assign a value to the declared variable. For e.g. x += 25 means x = x +25.
x = 100
y = 10
x += y
print(x) 110In this case, x+=y implies x=x+y which is x = 100 + 10.
Similarly, you can use x-=y, x*=y and x /=y
Python Data Structure
In every programming language, it is important to understand the data structures. Following are some data structures used in Python.
It is a sequence of multiple values. It allows us to store different types of data such as integer, float, string etc. See the examples of list below. First one is an integer list containing only integer. Second one is string list containing only string values. Third one is mixed list containing integer, string and float values.
- x = [1, 2, 3, 4, 5]
- y = [‘A’, ‘O’, ‘G’, ‘M’]
- z = [‘A’, 4, 5.1, ‘M’]
We can extract list item using Indexes. Index starts from 0 and end with (number of elements-1).
x = [1, 2, 3, 4, 5]
x Out: 1 x Out: 2 x Out: 5 x[-1] Out: 5 x[-2] Out: 4
x picks first element from list. Negative sign tells Python to search list item from right to left. x[-1] selects the last element from list.
You can select multiple elements from a list using the following method
x[:3] returns [1, 2, 3]
A tuple is similar to a list in the sense that it is a sequence of elements. The difference between list and tuple are as follows -
- A tuple cannot be changed once created whereas list can be modified.
- A tuple is created by placing comma-separated values inside parentheses ( ). Whereas, list is created inside square brackets [ ]
K = (1,2,3)Perform for loop on Tuple
City = ('Delhi','Mumbai','Bangalore')
for i in City:Read more (sections 3-5) here..