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

List methods


In this section, we will discuss list methods, one by one, with examples.

Let's make an empty list and add values one by one:

Avengers = []

In order to add a value to the list, we will use the append () method. You will see this method most of the time.

append ()

The syntax for the append () method is given as follows:

list.append () 

The method adds a value at the end of the list. Let's see the following example:

>>> Avengers = []

>>> Avengers.append("Captain-America")

>>> Avengers.append("Iron-man")

>>> Avengers

['Captain-America', 'Iron-man']

>>> 

You can see that we have added two members to the list.

Consider a situation where you want to add a list to an existing list. For example, we have two lists of our heroes:

Avengers1 = ['hulk', 'iron-man', 'Captain-America', 'Thor']

Avengers2 = ["Vision","sam"]

We want to add the Avengers2 list to the Avengers1 list. If you are thinking about the + operator, you might be right to some extent...