Book Image

Mastering matplotlib

By : Duncan M. McGreggor, Duncan M McGreggor
Book Image

Mastering matplotlib

By: Duncan M. McGreggor, Duncan M McGreggor

Overview of this book

Table of Contents (16 chapters)
Mastering matplotlib
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Python 3


On this note, it's probably good to discuss Python 3 briefly as there has been continued debate on the choice between the two most recent versions of the programming language (the other being the 2.7.x series). Python 3 represents a massive community-wide effort to adopt better coding practices as well as improvements in the maintenance of long-lived libraries, frameworks, and applications. The primary impetus and on-going strength of this effort, though, is a general overhaul of the mechanisms underlying Python itself. This will ultimately allow the Python programming language greater maintainability and longevity in the coming years, not to mention better support for the ongoing performance enhancements.

In case you are new to Python 3, the following table, which compares some of the major syntactical differences between Python 2 and Python 3, has been provided:

Syntactical Differences

Python 2

Python 3

Division with floats

x = 15 / 3.0

x = 15 / 3

Division with truncation

x = 15 / 4

x = 15 // 4

Longs

y = long(x * 10)

y = int(x * 10)

Not equal

x <> y

x != y

The unicode function

u = unicode(s)

u = str(s)

Raw unicode

u = ur"\t\s"

u = r"\t\s"

Printing

print x, y, z

print(x, y, z)

Raw user input

y = raw_input(x)

y = input(x)

User input

y = input(x)

y = eval(input(x))

Formatting

"%d %s" % (n, s)

"{} {}".format(n,s)

Representation

'x'

repr(x)

Function application

apply(fn, args)

fn(*args)

Filter

itertools.ifilter

filter

Map

itertools.imap

map

Zip

itertools.izip

zip

Range

xrange

range

Reduce

reduce

functools.reduce

Iteration

iterator.next()

next(iterator)

The execute code

exec code

exec(code)

The execute file

execfile(file)

exec(fh.read())

Exceptions

try:

...

except val, err:

...

try:

...

except val as err:

...