Book Image

Python Fundamentals

By : Ryan Marvin, Mark Nganga, Amos Omondi
Book Image

Python Fundamentals

By: Ryan Marvin, Mark Nganga, Amos Omondi

Overview of this book

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. 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. 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.
Table of Contents (12 chapters)
Python Fundamentals
Preface

Function Arguments


As mentioned earlier, parameters are the information that need to be passed to the function for it to do its work. Although parameters are also commonly referred to as arguments, arguments are thought of more as the actual values or references assigned to the parameter variables when a function is called at runtime. In simpler terms, arguments are to functions as ingredients are to a recipe.

Python supports several types of arguments; namely:

  • Required arguments

  • Keyword arguments

  • Default arguments

  • A variable number of arguments

Required Arguments

Required arguments are the types of arguments that have to be present when calling a function. These types of arguments also need to be in the correct order for the function to work as expected.

Consider the following code snippet:

def division(first, second):
  return first/second

You have to pass the arguments first and second for the function to work. You also have to pass the arguments in the correct order, as switching them will yield...