Module 1 ICP 1: Basics of Python - acikgozmehmet/PythonDeepLearning GitHub Wiki

Welcome to the PythonDeepLearning wiki!

Objectives:

We will focus on installation and getting familiar with python programming concepts.

Installations

Anaconda:

  1. Go to the following link https://www.anaconda.com/download/
  2. Download the installer and follow the default instructions for installation
  3. If you are unsure about any setting, accept the defaults. You can change them later.
  4. When installation is finished, from the Start menu, open the Anaconda Prompt. Type:
    conda create -n env_full anaconda python=3.6
  5. Go to your pycharm IDE, file, Setting and then choose project interpreter
  6. Finally in the Project Interpreter drop down list select the environment that you created

PyCharm:

  1. Go to the following link https://www.jetbrains.com/pycharm/download/#section=windows
  2. Download the Community Edition installer and follow the default instructions for installation
  3. If you are unsure about any setting, accept the defaults. You can change them later.

Overview

Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python's design philosophy emphasizes code readability with its notable use of significant whitespace.

General Information:

  • Unlike C/C++ or Java, Python statements do not end in a semicolon
  • In Python, indentation is the way you indicate the scope of a conditional, function, etc.
  • Look, no braces!
  • Python is interpretive.
  • You can just enter statements into the Python environment and they’ll execute
  • Python is object-oriented
  • Structure supports such concepts as polymorphism, operation overloading, and multiple inheritance.
  • Indentation is one of the greatest feature in Python.
  • It's free (open source)
  • It's powerful - Dynamic typing
    • Built-in types and tools
    • Library utilities
    • Third party utilities (e.g. Numeric, NumPy, SciPy)
    • Automatic memory management
  • It is portable
  • It's mixable
  • It's easy to use
  • It's easy to learn

In Class Programming

1. State differences between Python 2 and Python 3 version.

  • Python 3 is getting more popular because of the following improvements:
  • Python is not traditionally a typed language, but Python v3.5 supports typing, which removes development conflicts when working new pieces of code.
  • Each newer version of Python continues to get faster runtime. Meanwhile, nobody’s currently working to make Python 2.7 work faster.
  • Community support is better with Python 3.

Here are the important differences between Python 2.x and Python 3.x with examples

  • Division operator

    If we are porting our code or executing python 3.x code in python 2.x, it can be dangerous if integer division changes go unnoticed (since it doesn’t raise any error). It is preferred to use the floating value (like 7.0/5 or 7/5.0) to get the expected result when porting our code.

  • print function

    This is the most well-known change. In this, the print keyword in Python 2.x is replaced by the print() function in Python 3.x. However, parentheses work in Python 2 if a space is added after print keyword because the interpreter evaluates it as an expression.

  • Unicode In Python 2, implicit str type is ASCII. But in Python 3.x implicit str type is Unicode.

  • xrange

    xrange() of Python 2.x doesn’t exist in Python 3.x. In Python 2.x, range returns a list i.e. range(3) returns [0, 1, 2] while xrange returns a xrange object i. e., xrange(3) returns iterator object which work similar to Java iterator and generates number when needed.

  • Error Handling

    There is a small change in error handling in both versions. In python 3.x, ‘as’ keyword is required.

  • future module

    This is basically not a difference between the two versions, but a useful thing to mention here. The idea of future module is to help migrate to Python 3.x.

    If we are planning to have Python 3.x support in our 2.x code, we can use future imports in our code.

2. Write a python program for the following:

– Input the string “Python” as a list of characters from console, delete at least 2 characters, reverse the resultant string and print it.

Click here to get the source code

– Take two numbers from user and perform arithmetic operations on them.

Click here to get the source code

3. Write a program that accepts a sentence and replace each occurrence of ‘python’ with ‘pythons’ without using regex

Click here to get the source code

References

https://www.slideshare.net/nowells/introduction-to-python-5182313

https://www.slideshare.net/sujithkumar9212301/introduction-to-python-36647807

https://github.com/galactocalypse/python

http://www.cse.msu.edu/~cse231/PracticeOfComputingUsingPython/

https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2011/download-course-materials/

https://www.geeksforgeeks.org/important-differences-between-python-2-x-and-python-3-x-with-examples/