Python is an interpreted, interactive, object-oriented programming language. It incorporates modules, exceptions, dynamic typing, very high level dynamic data types, and classes. Python combines remarkable power with very clear syntax. It has interfaces to many system calls and libraries, as well as to various window systems, and is extensible in C or C++. It is also usable as an extension language for applications that need a programmable interface. Finally, Python is portable: it runs on many Unix variants, on the Mac, and on Windows 2000 and later.
All Python releases are Open Source. Historically, most, but not all, Python releases have also been GPL-compatible. The Licenses page details GPL-compatibility and Terms and Conditions.
IDLE is the Python IDE built with the
IDLE has the following features:
- coded in 100% pure Python, using the tkinter GUI toolkit
- cross-platform: works on Windows, Unix, and Mac OS X
- multi-window text editor with multiple undo, Python colorizing, smart indent, call tips, and many other features
- Python shell window (a.k.a. interactive interpreter)
- debugger (not complete, but you can set breakpoints, view and step)
Do the following:
- Click Start, point to All Programs, point to Python 3.4, and then click IDLE (Python GUI).
- Open IDLE
- Click File and then click New File
- Note: In Python V2 it would be
print 'Hello World!'
- Note: In Python V2 it would be
- Execute the code by pressing [F5]
The principal built-in types are numerics, sequences, mappings, classes, instances and exceptions.
Some collection classes are mutable. The methods that add, subtract, or rearrange their members in place, and don’t return a specific item, never return the collection instance itself but
Some operations are supported by several object types; in particular, practically all objects can be compared, tested for truth value, and converted to a string (with the
repr()function or the slightly different
str()function). The latter function is implicitly used when an object is written by the
message = 'Hello World!' print(message)
defintroduces a function definition. It must be followed by the function name and the parenthesized list of formal parameters. The statements that form the body of the function start at the next line, and must be indented.
message = 'Hello World!' def WriteMessage(): print(message) # Call the function WriteMessage()
Passing Variables to Functions
message was accessible because its scope was Global. You can pass variables and values to functions by appending those values to the function call. Also, your function must expect a value. In this example, we pass a string into the function that we declare as
def WriteMessage(message): print(message) # Call the function WriteMessage('Hello World!')
trystatement specifies exception handlers and/or cleanup code for a group of statements.
exceptclause(s) specify one or more exception handlers. When no exception occurs in the
tryclause, no exception handler is executed.
finallyis present, it specifies a ‘cleanup’ handler. The
tryclause is executed, including any
import sys, os def WriteMessage(message): print(message) try: # Call the function WriteMessage('Hello World!') except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename) print(exc_type, fname, exc_tb.tb_lineno) finally: # Write message WriteMessage('Finally...')
- The Python Software Foundation’s documenation for Python.
- The Python Wiki’s collection of programming guides, documentation, books, tools, and community.
- PTVS is a free, open source plugin that turns Visual Studio into a Python IDE.