Book Image

Learn Python in 7 Days

Book Image

Learn Python in 7 Days

Overview of this book

Python is a great language to get started in the world of programming and application development. This book will help you to take your skills to the next level having a good knowledge of the fundamentals of Python. We begin with the absolute foundation, covering the basic syntax, type variables and operators. We'll then move on to concepts like statements, arrays, operators, string processing and I/O handling. You’ll be able to learn how to operate tuples and understand the functions and methods of lists. We’ll help you develop a deep understanding of list and tuples and learn python dictionary. As you progress through the book, you’ll learn about function parameters and how to use control statements with the loop. You’ll further learn how to create modules and packages, storing of data as well as handling errors. We later dive into advanced level concepts such as Python collections and how to use class, methods, objects in python. By the end of this book, you will be able to take your skills to the next level having a good knowledge of the fundamentals of Python.
Table of Contents (18 chapters)
Title Page
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
2
Type Variables and Operators

Preface

Python was initially developed by Guido Von Rossum as a fun project and was named after his favorite show Monty Python's Flying Circus. It was developed in 1991, but it started becoming popular around 2008. A major contributor to this popularity was Google, which has developed a number of platforms using Python. Recently, Python has been popularized by cloud, DevOps, data science, data analytics, machine learning, and natural language processing. With more and more data harvesting and data processing, people want to get into new types of job roles, which require basic programming skills, and Python perfectly suits all the categories of job work. Learn Python in 7 Days has been designed to give such people an easy way to learn and master the basics of Python in 7 days. The book covers the basic and necessary concepts that are required to understand the working of the Python language. The book is for all types of readers and learners. It also acts as a refresher for experienced people. We believe that we have covered as much as possible for making it a book to be finished in seven days; however, we believe that merely reading the book is not sufficient to master programming skills. It will take more than that to achieve mastery. We hope you enjoy reading the book and use it as a good learning book.

What this book covers

Chapter 1Getting Started with Python, gives you the background of Python programming language, along with installation instructions and basic commands.

Chapter 2, Type Variables and Operators, gives you an idea of variable types and the various types of operators used in Python.

Chapter 3, Strings, sheds light on various strings and string operations in Python.

Chapter 4, Lists, gives the idea of one of the important collection types, called lists, available in Python and all the relevant operations that could be done on lists.

Chapter 5, Dictionary, covers another important collection type available in Python and deals with the basics of dictionary and the various operations on a dictionary.

Chapter 6, Control Statements and Loops, discusses about various control statements, such as if statement, and loops (for, while, and so on), which could be used to write a piece of code in Python.

Chapter 7, Function and Scope of Variable, gives you an idea about functions that could be user-defined or built in. The chapter talks about the basics of a function and various operations. Also, the chapter gives you an idea about the validity of a variable within the particular scope of the code block.

Chapter 8, Modules and Packages, discusses about various modules and packages that are available in Python and also how to create your own package and module.

Chapter 9, File Handling and Exceptions, is divided into two parts; the first part deals with different file handling operations and the second part deals with exception handling.

Chapter 10, Collections, gives you the primer for different types and subtypes of collections in Python and explains the basic operations that could be done on them.

Chapter 11, Class and Objects, finally gives you an idea about some object-oriented programming concepts that are available in Python.

 

What you need for this book

For this book, you need to install Python 2.7x version on your machine, along with a simple text editor (Notepad or Notepad++). All the examples are meant to be run on the Python 2.7 version and will not work in Python 3.x versions.

Who this book is for

This book is intended for people who have zero to some background in computer programming. It is also intended for people who want to have some refresher in Python programming.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The next step is to edit build.properties file."

A block of code is set as follows:

print "Name Marks Age" 
print ( "%s %14.2f %11d" % ("John Doe", 80.67, 27)) 
print ( "%s %12.2f %11d" %("Bhaskar" ,76.901, 27))
print ( "%s %3.2f %11d" %("Mohit", 56.98, 25)) 

Any command-line input or output is written as follows:

    $ brew install python

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Once done, click on Activate."

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at https://github.com/PacktPublishing/Learn-Python-in-7-days. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Java-9-Programming-By_Example. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.