Thu 03 Aug 2017 10:15:06 AM -03

Learning Python

Which version to start? 2.x or 3.x?

Short answer: start learning 3.x and, if needed, check the differences with 2.x.

From Should I use Python 2 or Python 3 for my development activity?:

Besides, several aspects of the core language (such as print and exec being
statements, integers using floor division) have been adjusted to be easier for
newcomers to learn and to be more consistent with the rest of the language, and
old cruft has been removed (for example, all classes are now new-style,
"range()" returns a memory efficient iterable, not a list as in 2.x).

[...]

In particular, instructors introducing Python to new programmers should
consider teaching Python 3 first and then introducing the differences in Python
2 afterwards (if necessary), since Python 3 eliminates many quirks that can
unnecessarily trip up beginning programmers trying to learn Python 2.

Also:

General

  • Everything is an object. Really? What about symbols like + - and =?
  • The dir() and help() functions are really useful.
  • Great idea: iteration protocol.
  • There are sequences and sum operations common for all types and specific type operations.

Iteration and optimization

In general, leading and trailing double underscores is the naming pattern
Python uses for implementation details. The names without the underscores in
this list are the callable methods on string objects.

Polymorphism

Python encourages polymorphism:

This is related to the idea of polymorphism mentioned earlier, and it stems
from Python’s lack of type declarations. As you’ll learn, in Python, we code to
object interfaces (operations supported), not to types. That is, we care what
an object does, not what it is. Not caring about specific types means that code
is automatically applicable to many of them—any object with a compatible
interface will work, regardless of its specific type. Although type checking is
supported—and even required in some rare cases—you’ll see that it’s not usually
the “Pythonic” way of thinking. In fact, you’ll find that polymorphism is
probably the key idea behind using Python well.

Numeric Display Formats

Types

More formally, there are three major type (and operation) categories in Python
that have this generic nature:

Numbers (integer, floating-point, decimal, fraction, others)
Support addition, multiplication, etc.
Sequences (strings, lists, tuples)
Support indexing, slicing, concatenation, etc.
Mappings (dictionaries)
Support indexing by key, etc.

[...]

The major core types in Python break down as follows:

Immutables (numbers, strings, tuples, frozensets)
None of the object types in the immutable category support in-place changes,
though we can always run expressions to make new objects and assign their
results to variables as needed.

Mutables (lists, dictionaries, sets, bytearray)
Conversely, the mutable types can always be changed in place with operations
that do not create new objects. Although such objects can be copied, in-place
changes support direct modification.

So remember that when copying or referencing a list.

Nice stuff

Implementations

Libraries and applications

Frameworks

IDEs

Test projects