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

Handling Structured Data


Now that you have a good handle on reading and writing to files, let's talk about how to deal with more structured data. In real-world applications, you will most likely have to read data in a structured format.

Do you remember the payroll application we talked about in the beginning of this chapter? Such data could be represented in a CSV file. A CSV file is a file with comma-separated values, usually arranged in columns.

Such data can then be easily read into a spreadsheet application, such as Excel, and manipulated there. Python provides a utility to work with CSV files, which we will cover in this topic.

Here is an example of a CSV file:

Name,City
"Nash, Colorado B.",Milton Keynes
"Herrera, Chase E.",Gentbrugge
"Hubbard, Leilani I.",Bremen
"Vinson, Marsden H.",Lakeland County
"Macias, Lawrence E.",Noisy-le-Grand
…
…
"Phelps, Amity V.",Morena
"Woods, Jaden V.",Portland
"Hyde, Duncan P.",Schellebelle
"Hendricks, Yoshio V.",Sperlinga
"Delgado, Emma T.",Reyhanlı
"Oneil...