background preloader

3. An Informal Introduction to Python — Python v2.7.2 documentation In the following examples, input and output are distinguished by the presence or absence of prompts (>>> and …): to repeat the example, you must type everything after the prompt, when the prompt appears; lines that do not begin with a prompt are output from the interpreter. Note that a secondary prompt on a line by itself in an example means you must type a blank line; this is used to end a multi-line command. Many of the examples in this manual, even those entered at the interactive prompt, include comments. Comments in Python start with the hash character, #, and extend to the end of the physical line. Let’s try some simple Python commands. 3.1.1. The interpreter acts as a simple calculator: you can type an expression at it and it will write the value. The integer numbers (e.g. 2, 4, 20) have type int, the ones with a fractional part (e.g. 5.0, 1.6) have type float. The return type of a division (/) operation depends on its operands. 3.1.2. >>> '"Isn\'t," they said.''" See also 3.1.3.

The Python Tutorial — Python v2.7 documentation 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 Python interpreter is easily extended with new functions and data types implemented in C or C++ (or other languages callable from C). This tutorial introduces the reader informally to the basic concepts and features of the Python language and system. For a description of standard objects and modules, see The Python Standard Library. The Glossary is also worth going through.

Dive Into Python 3 You are here: • Dive Into Python 3 Dive Into Python 3 covers Python 3 and its differences from Python 2. Compared to Dive Into Python, it’s about 20% revised and 80% new material. The book is now complete, but feedback is always welcome. Table of Contents (expand) Also available on dead trees! The book is freely licensed under the Creative Commons Attribution Share-Alike license. you@localhost:~$ git clone © 2001–11 Mark Pilgrim

Python Programming Python Programming From Wikibooks, open books for an open world Jump to: navigation, search This book describes Python, an open-source general-purpose interpreted programming language available for a broad range of operating systems. Contents[edit] Intro[edit] Overview Getting Python Setting it up Interactive mode Self Help Basics[edit] Creating Python programs Variables and Strings Basic syntax Sequences (Strings, Lists, Tuples, Dictionaries, Sets) Data types Numbers Strings Lists Tuples Dictionaries Sets Basic Math -- redundant to "Operators" Operators Control Flow Decision Control Conditional Statements Loops Functions Scoping Input and output Files Text Modules Classes Exceptions Errors Source Documentation and Comments Idioms Advanced[edit] Decorators Context Managers Reflection Metaclasses Namespace Tips and Tricks Modules[edit] Standard library modules[edit] Standard Library Regular Expression External commands XML Tools Email Threading Sockets GUI Programming Tkinter CGI interface WSGI web programming Extracting info from web pages Math

PEP 8 -- Style Guide for Python Code Code should be written in a way that does not disadvantage other implementations of Python (PyPy, Jython, IronPython, Cython, Psyco, and such).For example, do not rely on CPython's efficient implementation of in-place string concatenation for statements in the form a += b or a = a + b. This optimization is fragile even in CPython (it only works for some types) and isn't present at all in implementations that don't use refcounting. In performance sensitive parts of the library, the ''.join() form should be used instead. This will ensure that concatenation occurs in linear time across various implementations.Comparisons to singletons like None should always be done with is or is not, never the equality operators.Also, beware of writing if x when you really mean if x is not None -- e.g. when testing whether a variable or argument that defaults to None was set to some other value.

Free Online Course Materials Building Skills in Python — S.Lott v4.2 Site How do you learn Python? By doing a series of exercises, each of which adds a single new feature of the language. This 450+ page book has 42 chapters that will help you build Python programming skills through a series of exercises. This book includes six projects from straight-forward to sophisticated that will help solidify your Python skills. The 2.6 edition was significantly revised and expanded to cover Python 2.6 and some elements of Python 3.1. Many chapters have been updated, reorganized and added since the 2.5 edition. The current release has benefitted from a great deal of support from readers who sent detailed lists of errors and suggestions. Professional programmers who need to learn Python are this book’s primary audience. Since Python is simple, we can address newbie programmers who don’t have deep experience in a number of other languages.

How to Think Like a Computer Scientist — How to Think Like a Computer Scientist: Learning with Python 3 Version date: October 2012 by Peter Wentworth, Jeffrey Elkner, Allen B. Downey, and Chris Meyers (based on 2nd edition by Jeffrey Elkner, Allen B. Corresponding author: Source repository is at For offline use, download a zip file of the html or a pdf version (the pdf is updated less often) from Search PageCopyright NoticeForewordPrefacePreface-3 This Rhodes Local Edition (RLE) of the bookContributor ListChapter 1 The way of the programChapter 2 Variables, expressions, and statementsChapter 3 Hello, little turtles!

6. Built-in Exceptions — Python v3.1.3 documentation In Python, all exceptions must be instances of a class that derives from BaseException. In a try statement with an except clause that mentions a particular class, that clause also handles any exception classes derived from that class (but not exception classes from which it is derived). Two exception classes that are not related via subclassing are never equivalent, even if they have the same name. The built-in exceptions listed below can be generated by the interpreter or built-in functions. User code can raise built-in exceptions. The built-in exception classes can be sub-classed to define new exceptions; programmers are encouraged to at least derive new exceptions from the Exception class and not BaseException. The following exceptions are used mostly as base classes for other exceptions. exception BaseException The base class for all built-in exceptions. exception Exception All built-in, non-system-exiting exceptions are derived from this class. exception ArithmeticError