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, https://www.python.org/, 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.
This tutorial introduces the reader informally to the basic concepts and features of the Python language and system. It helps to have a Python interpreter handy for hands-on experience, but all examples are self-contained, so the tutorial can be read off-line as well.
An excellent way to see how Python code works is to run the Python interpreter and type code right into it. If you ever have a question like, "What happens if I add an
int
to a list
?" Just typing it into the Python interpreter is a fast and likely the best way to see what happens. (See below to see what really happens!)$ python ## Run the Python interpreter
Python 2.7.9 (default, Dec 30 2014, 03:41:42) [GCC 4.1.2 20080704 (Red Hat 4.1.2-55)] on linux2Type "help", "copyright", "credits" or "license" for more information.
>>> a = 6 ## set a variable in this interpreter session
>>> a ## entering an expression prints its value
6
>>> a + 2
8
>>> a = 'hi' ## 'a' can hold a string just as well
>>> a'hi'
>>> len(a) ## call the len() function on a string
2
>>> a + len(a) ## try something that doesn't work
Traceback (most recent call last):
File "", line 1, in
TypeError: cannot concatenate 'str' and 'int' objects>>> a + str(len(a)) ## probably what you really wanted
'hi2'
>>> foo ## try something else that doesn't work
Traceback (most recent call last):
File "", line 1, in
NameError: name 'foo' is not defined
>>> ^D ## type CTRL-d to exit (CTRL-z in Windows/DOS terminal)
An Overview of Python
What is Python?
- Interpreted languages
- Advantages and disadvantages
- Downloading and installing
- Which version of Python
- Where to find documentation
Running Python Scripts
- Structure of a Python script
- Using the interpreter interactively
- Running standalone scripts under Unix and Windows
Getting Started
- Using variables
- String types: normal, raw and Unicode
- String operators and expressions
- Math operators and expressions
- Writing to the screen
- Command line parameters
- Reading from the keyboard
Flow Control
- About flow control
- Indenting is significant
- The if and elif statements
- while loops
- Using lists
- Using the for statement
- The range() function
Sequence Data
- list operations
- list methods
- Strings are special kinds of lists
- tuples
- sets
- Dictionaries
Defining Functions
- Syntax of function definition
- Formal parameters
- Global versus local variables
- Passing parameters and returning values
Working with Files
- Text file I/O overview
- Opening a text file
- Reading text files
- Raw (binary) data
- Using the pickle module
- Writing to a text file
Dictionaries and Sets
- Dictionary overview
- Creating dictionaries
- Dictionary functions
- Fetching keys or values
- Testing for existence of elements
- Deleting elements
- Errors and Exception Handling
- Dealing with syntax errors
- Exceptions
- Handling exceptions with try/except
- Cleaning up with finally
Using Modules
- What is a module?
- The import statement
- Function aliases
- Packages
Regular Expressions
- RE Objects
- Pattern matching
- Parsing data
- Subexpressions
- Complex substitutions
- RE tips and tricks
Highlights of the Standard Library
- Working with the operating system
- Grabbing web pages
- Sending email
- Using glob for filename wildcards
- math and random
- Accessing dates and times with datetime
- Working with compressed files
An Introduction to Python Classes
- About o-o programming
- Defining classes
- Constructors
- Instance methods
- Instance data
- Class methods and data
- Destructor’s
0 comments:
Post a Comment