Dataacademy@doc.gov Star Ying Introduction to …

Introduction to Python

Star Ying dataacademy@

Based on Google's Python Class

Background

Python is a popular, object-oriented, and structured programming language. It's design is guided by the `Zen of Python' software principles.

Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently unless explicitly silenced.

In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than right now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea--let's do more of those!

3

Extending Python

Python is highly extensible. Besides the core functionality of Python, packages for Python can be imported to obtain additional functionality through conda or pip. You should have installed the following packages prior to class: ujson numpy scipy

4

Editing Python

A Python program is just a text file that you edit directly. The program typically is saved with a .py extension to differentiate. Using an editor designed for programming is preferred. Do not use Wordpad or Notepad. You should have one of the following installed prior to class: Sublime Atom Notepad++

5

Python Interpreter

The Python interpreter can be called by itself. This can allow you to experiment with commands and syntax as you write your program. To call the Python interpreter itself: python To pass a Python program to the interpreter: python program.py

6

Hello World

print `Hello World'

7

Hello World

print `Hello World' # But not goodbye

8

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download