Skip to main content

2016 | Buch

Programming with Python

insite
SUCHEN

Über dieses Buch

Based on the latest version of the language, this book offers a self-contained, concise and coherent introduction to programming with Python. The book’s primary focus is on realistic case study applications of Python. Each practical example is accompanied by a brief explanation of the problem-terminology and concepts, followed by necessary program development in Python using its constructs, and simulated testing. Given the open and participatory nature of development, Python has a variety of incorporated data structures, which has made it difficult to present it in a coherent manner. Further, some advanced concepts (super, yield, generator, decorator, etc.) are not easy to explain. The book specially addresses these challenges; starting with a minimal subset of the core, it offers users a step-by-step guide to achieving proficiency.

Inhaltsverzeichnis

Frontmatter
Chapter 1. Python–A Calculator
Abstract
Whether new to Python or to programming one can start working in Python directly without any formal introduction to syntax, semantics, and so on. The introduction here is like that to a calculator with the basic algebraic operations. The operator symbols and simple code structure are introduced through this.
T. R. Padmanabhan
Chapter 2. Algebra with Variables
Abstract
Variable as an entity has been introduced. It can be an integer, a number—real or complex, a string of characters or results of operations carried out with them. The built-in functions in Python are the commonly used ones with variables. These can be algebraic or logical ones represented by identified symbols or names. Significance of keywords has been brought out. Formation of strings and simple direct printing (being needed with many programs) are explained through illustrations. The exercises at the end of the chapter help in practice and build up of confidence in using Python.
T. R. Padmanabhan
Chapter 3. Simple Programs
Abstract
Normally a computational task is spelt out in pseudo code form or as a flowchart. Forming the program code with this as guide is good practice. The task can be simple and direct or conditional. The latter is often realized using keywords like while or if. They are explained through clear and focused examples. The idea of iterative routines, their convergence to a solution of desired accuracy using judgment based on metrics to stop iteration—all these go with these. A few widely used approaches to iterative solutions are explained here. The variety of exercises given, help in understanding the types of tasks as well as possible iterative procedures.
T. R. Padmanabhan
Chapter 4. Functions and Modules
Abstract
The function as carrying out a set of operations and returning an object is basic to Python. Functions, lambda as the elegant anonymous one-line function, nested functions, and recursive functions are all discussed with illustrations. Local, non-local, and global sift out the scope of entities in nested schemes. A module has functions and stand alone statements within it. A module can be imported into any environment and its functions used contextually. Math is a key built-in module in Python with the exponential, trigonometric, and related functions as its main contents. Use of these from the math module, to suit contexts, is illustrated through examples.
T. R. Padmanabhan
Chapter 5. Sequences and Operations with Sequences
Abstract
The possibility of representing sequences in different ways is one of the unique features of Python. The functions and methods available to process them add an additional dimension to their use. Sequences and operations (Rossum and Drake 2014) with them is the focus of this chapter.
T. R. Padmanabhan
Chapter 6. Additional Operations with Sequences
Abstract
Diverse operations with sequences extend their utility considerably. Operations specific to sets including comparisons and those with dictionaries are discussed separately to bring out their significance. * and ** with values and keys fit well with respective collections without the prior knowledge of their respective sizes. The exercises given are representative for sequence specific applications.
T. R. Padmanabhan
Chapter 7. Operations for Text Processing
Abstract
Information is printed/displayed in natural language character combinations. But computer communication and storage systems use only bit streams. Unicode which defines universally accepted conversion between character and bit streams is the basis to bridge the gap between the two. Different coding schemes of conversion are in vogue—UTF8 being the most widely used one. UTF8 is explained and coding/decoding related constructs in Python dealt with in detail. Character streams as strings and binary string related operations are treated comprehensively. ‘Bytes’ and ‘bytearray’ as sequence representations and number representations in different forms (binary, octal, hex, decimal, and radix-specified) and their conversions come in handy here. Exercises provided are in classical cryptography, cryptanalysis, and selected coding schemes; these are useful in relating Python operations with characters effectively.
T. R. Padmanabhan
Chapter 8. Operations with Files
Abstract
The print function for output (on the lines of C language) was in vogue prior to Python 3. The same is essentially retained in Python 3 for continuity. But with Python 3 the focus is on string formation and print is a function. With this elegant demarcation string formation and its nuances are dealt with in depth. With files as strings of characters or binary stream all file related operations fall in neatly.
T. R. Padmanabhan
Chapter 9. Application Modules
Abstract
The built-in modules that come in handy for the programmer (in his tasks) form the focus of this chapter. Random numbers, random sequences, and related operations are dealt with. Similarly the commonly used distribution functions and related constructs are explained. Use of array for number representations and its manipulations is efficient in terms of storage and execution. The bisect module with its operations complement this as well as string related work. When the focus of operation is on an extremum element of any sequence, heapq with its methods is fast in execution; explanation of its operation and tracking movement of elements when the heap is popped or pushed aids in effective grasp of heapq. The interesting exercises at the end of the chapter complement those on sequences in Chaps. 5 and 6.
T. R. Padmanabhan
Chapter 10. Classes and Objects
Abstract
Object as a concept is omnipresent in Python. Assignments remain pointers to the ID of the objects as long as the object is not modified. Clarity brought out through examples as done here goes a long way in grasping Python’s data structures. Class, its initialization, and its functions as attributes are all explained through examples. Overloading transforms many of the built-in functions and operations into generic ones. Its added dimension is brought out through examples. Instantiations in multiply linked class definitions are explained. Super as a construct provides a structured and logical basis for instantiation with multiple inheritance set ups. Examples considered here enhance understanding of the nuances. Direct command line execution of Python script with its associated flexibility is also dealt with here.
T. R. Padmanabhan
Chapter 11. Time Related Operations
Abstract
The three time and calendar related modules and operators in them are dealt with here. UTC and ISO8601 are used to express and represent time and time intervals; they are explained and the use of all related constructs illustrated. With epoch as reference date, time, their combinations, relations with time zone, and geographic locations are possible to be expressed and related in different ways. Access to calendar and calendar formation to different formats are also made possible. ‘Timeit’ module provides the framework to compare the efficacy of different routines and can be of use in code optimization.
T. R. Padmanabhan
Chapter 12. Functional Programming Aids
Abstract
The modules available as functional programming aids are dealt with here. The built-in functions for algebra and logic operation are defined as convenient functions in the operator module. ‘Itemgetter’, ‘attrgetter’ and ‘methodcaller’ are available as generic methods. ‘inplace’ operators corresponding to all composite algebraic and logic operations are available as corresponding useful functions. Compact iterators formed around common functions are available in ‘itertools’. Their use is illustrated. The yield construct is for transforming a function into a corresponding generator. Going a step further ‘yield from’ chains generators for multiple sequences. Decorator provides an elegant template for nested suites. Their use is illustrated through examples. A number of readymade decorators and functions in the ‘functools’ module have been explained through illustrative examples.
T. R. Padmanabhan
Backmatter
Metadaten
Titel
Programming with Python
verfasst von
T R Padmanabhan
Copyright-Jahr
2016
Verlag
Springer Singapore
Electronic ISBN
978-981-10-3277-6
Print ISBN
978-981-10-3276-9
DOI
https://doi.org/10.1007/978-981-10-3277-6