**.**

**1. Getting Started with Python**

**Python 2.7 vs 3.6**

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.

**Python for Data Science**

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.

*Do you know these sites are developed in Python?*- YouTube
- Dropbox
- Disqus

**How to Install Python**

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

**Coding Environments**

- Jupyter (Ipython) Notebook
- Spyder

**Spyder**. It is like RStudio for Python. It gives an environment wherein writing python code is user-friendly. If you are a SAS User, you can think of it as SAS Enterprise Guide / SAS Studio. It comes with a syntax editor where you can write programs. It has a console to check each and every line of code. Under the 'Variable explorer', you can access your created data files and function.

**I highly recommend Spyder!**

**.**

Spyder - Python Coding Environment |

**Jupyter (Ipython) Notebook**

**Spyder Shortcut Keys**

**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*Arithmetic Operators | Operation | Example |
---|---|---|

+ | 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 |

**Basic Programs**

**Example 1**

#Basics

x = 10

y = 3

print("10 divided by 3 is", x/y)

print("remainder after 10 divided by 3 is", x%y)

**Result :**

10 divided by 3 is 3.33

remainder after 10 divided by 3 is 1

**Example 2**

x = 100

x > 80 and x <=95

x > 35 or x < 60

x > 80 and x <=95 Out[45]: False

x > 35 or x < 60 Out[46]: 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) |

**Assignment Operators**

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)

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

**2. Data Structures and Conditional Statements**

**Python Data Structure**

In every programming language, it is important to understand the data structures. Following are some data structures used in Python.

**1. List**

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’]

**Get List Item**

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[0]

x[1]

x[4]

x[-1]

x[-2]

x[0] Out[68]: 1 x[1] Out[69]: 2 x[4] Out[70]: 5 x[-1] Out[71]: 5 x[-2] Out[72]: 4

**x[0]**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]

**2. Tuple**

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**[ ]**

**Examples**

K = (1,2,3)

City = ('Delhi','Mumbai','Bangalore')

**Perform for loop on Tuple**

for i in City:

print(i)

*Read more (sections 3-5) here..*

## You need to be a member of Data Science Central to add comments!

Join Data Science Central