Python - Get Started

Introduction

Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming.

Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.

The Python interpreter and the extensive standard library are freely available in source or binary form for all major platforms from the Python Web site, and may be freely distributed. The same site also contains distributions of and pointers to many free third party Python modules, programs and tools, and additional documentation.

The Python interpreter is easily extended with new functions and data types implemented in C or C++ (or other languages callable from C). Python is also suitable as an extension language for customizable applications.

Preparation

Python Installation

Install Python on windows

You can visit https://www.python.org/ to download the latest python version which is suitable for your OS.

Note: DO check Add Python 3.6 to path when installing Python otherwise you should add python.exe to Path manually.

IDEs

Here we introduce several IDEs for writing, testing and debugging your python code. 

  • PyCharm

  • Spyder 
  • Rodeo
  • Atom
  • Jupyter Notebook

More details can be found at https://www.datacamp.com/community/tutorials/data-science-python-ide. You can find the features of each IDE and choose the suitable IDE.

Basic Syntax

 Python is easy to use if you have the experience with other programming languages. 

 Here we introduce some basic syntaxes of python which are different from other programming languages.

Lines and Indentation

Python provides no braces to indicate blocks of code for class and function definitions or flow control. Blocks of code are denoted by line indentation, which is rigidly enforced.

The number of spaces in the indentation is variable, but all statements within the block must be indented the same amount. For example:

if True:

   print "True"

else:

   print "False"

Multi-Line Statements

Statements in Python typically end with a new line. Python does, however, allow the use of the line continuation character (\) to denote that the line should continue. For example −

total = item_one + \

        item_two + \

        item_three

Statements contained within the [], {}, or () brackets do not need to use the line continuation character. For example −

days = ['Monday''Tuesday''Wednesday',

        'Thursday''Friday']

Comments in Python

A hash sign (#) that is not inside a string literal begins a comment. All characters after the # and up to the end of the physical line are part of the comment and the Python interpreter ignores them.

猜你喜欢

转载自blog.csdn.net/bettyHHUC/article/details/89885386