June 2017
Beginner
352 pages
8h 39m
English
You can get a long way in Python using the built in scalar and collections types. For many problems the built in types, together with those available in the Python Standard Library, are completely sufficient. Sometimes though, they aren't quite what's required, and the ability to create custom types is where classes come in.
As we've seen, all objects in Python have a type, and when we report that type using the type() built-in function the result is couched in terms of the class of that type:
>>> type(5)<class 'int'>>>> type("python")<class 'str'>>>> type([1, 2, 3])<class 'list'>>>> type(x*x for x in [2, 4, 6])<class 'generator'>
A class is used to define the structure and behaviour of one or more objects, ...
Read now
Unlock full access