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

Pass by reference versus pass by value


Pass by reference is the term used in some programming languages, where values to the argument of the function are passed by reference, that is, the address of the variable is passed and then the operation is done on the value stored at these addresses. 

Pass by value means that the value is directly passed as the value to the argument of the function. In this case, the operation is done on the value and then the value is stored at the address.

In Python arguments, the values are passed by reference. During the function call, the called function uses the value stored at the address passed to it and any changes to it also affect the source variable:

def pass_ref(list1): 
 list1.extend([23,89]) 
 print "list inside the function: ",list1 
list1 = [12,67,90] 
print "list before pass", list1
pass_ref(list1) 
print "list outside the function", list1

Here, in the function definition, we pass the list to the pass_ref function and then we extend the list to add...