Book Image

Python Fundamentals

By : Ryan Marvin, Mark Ng’ang’a, Amos Omondi
Book Image

Python Fundamentals

By: Ryan Marvin, Mark Ng’ang’a, Amos Omondi

Overview of this book

<p>After a brief history of Python and key differences between Python 2 and Python 3, you'll understand how Python has been used in applications such as YouTube and Google App Engine. As you work with the language, you'll learn about control statements, delve into controlling program flow and gradually work on more structured programs via functions.</p> <p>As you settle into the Python ecosystem, you'll learn about data structures and study ways to correctly store and represent information. By working through specific examples, you'll learn how Python implements object-oriented programming (OOP) concepts of abstraction, encapsulation of data, inheritance, and polymorphism. You'll be given an overview of how imports, modules, and packages work in Python, how you can handle errors to prevent apps from crashing, as well as file manipulation.</p> <p>By the end of this book, you'll have built up an impressive portfolio of projects and armed yourself with the skills you need to tackle Python projects in the real world.</p>
Table of Contents (12 chapters)
Python Fundamentals
Preface

The range Function


Python's range function is a built-in function that generates a list of numbers. This list is mostly used to iterate over using a for loop.

This function is used when you want to perform an action a predetermined number of times, where you may or may not care about the index, for instance, finding or calculating all even numbers between 0 and 100, where Python will list or print out all even numbers in that range, excluding 100, even though it is an even number. You can also use it to iterate over a list (or another iterable) while keeping track of the index.

The basic syntax of the range function is as follows:

range([start], stop, [step])

Here is a breakdown of what each parameter does:

  • start: This is the starting number of the sequence.

  • stop: This means generate numbers up to but not including this number.

  • step: This is the difference between each number in the sequence.

As a general rule, when a parameter is enclosed in square brackets [] in the function definition, it means...