O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Learn Python in 7 Days

Book Description

Learn efficient Python coding within 7 days

About This Book

  • Make the best of Python features
  • Learn the tinge of Python in 7 days
  • Learn complex concepts using the most simple examples

Who This Book Is For

The book is aimed at aspiring developers and absolute novice who want to get started with the world of programming. We assume no knowledge of Python for this book.

What You Will Learn

  • Use if else statement with loops and how to break, skip the loop
  • Get acquainted with python types and its operators
  • Create modules and packages
  • Learn slicing, indexing and string methods
  • Explore advanced concepts like collections, class and objects
  • Learn dictionary operation and methods
  • Discover the scope and function of variables with arguments and return value

In Detail

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.

Style and approach

Fast paced guide to get you up-to-speed with the language. Every chapter is followed by an exercise that focuses on building something with the language. The codes of the exercises can be found on the Packt website

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. Getting Started with Python
    1. Why Python?
      1. Python applications
      2. Versions
      3. Implementations of Python
    2. Installation
      1. Installation on Windows platform
      2. Installation on Linux platform
      3. Installation on Mac OS
    3. Notepad++ installation
      1. Python file formats
      2. Python interactive shell
      3. System or environment variables
        1. Setting environment variables in Windows
        2. Setting environment variables in Linux
        3. Setting environment variables in Mac OS (OS 10.9)
    4. Writing a simple Hello World! program
    5. Basic Python syntax
      1. Comments in Python
      2. Triple, double and single quotes
      3. Python back slash
      4. String inside the quotes
      5. Escape sequence in Python
      6. String concatenation
      7. Formatted output
      8. Indentation
    6. Summary
  3. Type Variables and Operators
    1. Variables
      1. Single assignment
      2. Multiple assignment
      3. Data types in Python
        1. Numeric data types or numbers
          1. Integers and long integers
          2. Floating point numbers
          3. Complex numbers
          4. Boolean data type
          5. String data types
      4. American Standard Code for Information Interchange (ASCII) character sets
      5. Conversion functions
      6. Arithmetic expressions
        1. Mixed mode arithmetic
          1. Mixed Mode Conversion
      7. Type conversions
    2. Operators
      1. Arithmetic operators
      2. Comparison operators
      3. Variants of assignment operator
      4. Bitwise operators
      5. Logical operators
      6. Membership operators
      7. Identity operators
      8. Operator precedence
    3. Summary
  4. Strings
    1. Python strings
      1. The subscript operator
    2. Slicing for substrings
    3. Python string methods
      1. String case methods
      2. String strip methods
      3. String split methods
      4. String justify methods
      5. String Boolean methods
    4. String functions
    5. Tuple
      1. Creating an empty tuple
      2. Creating tuple with elements
      3. Indexing tuple
      4. Slicing of tuple
      5. Unpacking the items of tuples
    6. Tuple functions
    7. Operations of tuples
    8. Exercise
    9. Summary
  5. Lists
    1. Creating a list
      1. Creating a list with values
        1. Unpacking list values
    2. List operations
      1. Accessing list values
      2. Slicing the list
      3. Updating the list
      4. Deleting values from a list
      5. Addition of Python lists
      6. Multiplication of lists
    3. in operator
    4. List functions
      1. len()
      2. max ()
      3. list ()
      4. sorted ()
    5. List methods
      1. append ()
      2. extend ()
      3. Difference between append and extend.
      4. count ()
      5. index ()
      6. insert()
      7. remove()
      8. pop()
      9. reverse()
    6. List comprehensions
    7. Exercises
    8. Summary
  6. Dictionary
    1. Overview of dictionary
    2. Operations on the dictionary
      1. Accessing the values of dictionary
      2. Deleting an item from the dictionary
      3. Updating the values of the dictionary
      4. Adding an item to the dictionary
    3. Dictionary functions
      1. len()
      2. str()
      3. max()
      4. min()
      5. dict()
    4. Dictionary methods
      1. copy()
      2. get()
      3. setdefault()
      4. has_key()
      5. keys()
      6. values()
      7. update()
      8. items()
      9. clear()
    5. Python dictionary with for loop
      1. Practical program
    6. Exercise
    7. Summary
  7. Control Statements and Loops
    1. Control statements
    2. The if and if...else statement
    3. The if...elif...else statement
    4. Loops
      1. Types of loops
        1. Definite loop
        2. Indefinite loop
          1. The while True and break statement
          2. The break statement
      2. Nested loops
        1. The continue and pass statements
        2. The pass statement
    5. Summary
  8. Function and Scope of Variable
    1. Functions
      1. Categories of functions
        1. Built-in functions
        2. User-defined functions
          1. Function definition
          2. Calling a function
          3. Function with arguments
          4. Function with an argument and return type
          5. Function with default argument
          6. Function with variable length argument
          7. Key-value pair as variable length argument
    2. Pass by reference versus pass by value
    3. Scope of variables
    4. Memory management
    5. Summary
  9. Modules and Packages
    1. Modules
    2. The import statement
    3. Locating Python modules
    4. Compiled Python files
    5. The Python package
    6. Summary
  10. File Handling and Exceptions
    1. Reading text from a file
      1. The read() method
      2. The readline() method
      3. The readlines() method
      4. Exercise
    2. Writing text to a file
      1. Examples
    3. Pickling
    4. Unpickling
    5. Exceptions
      1. The try statement with an except clause
      2. Multiple exception blocks
      3. The try...finally statement
      4. The exception argument
      5. Raising exceptions
      6. User-defined exceptions
    6. Summary
  11. Collections
    1. Collections
      1. Counter
        1. Update function
          1. Usage of counters
          2. Operations of Python collection counter
      2. Deque
        1. Populating deque
        2. Deque consumption
        3. Deque rotation
      3. Ordered dictionary
        1. Sorting of ordered dictionary based upon keys
        2. Sorting of ordered dictionary based upon values
      4. Default dictionary
        1. Sample problem solved by the default dictionary - scenario one
        2. Sample problem solved by the default dictionary - scenario two
      5. Named tuple
        1. Adding values and creating a dictionary
    2. Summary
  12. Class and Objects
    1. Object-oriented programming overview
      1. Key concepts
      2. Creating a class
    2. Instance variables
    3. The __init__ method
    4. Class variables
    5. Class inheritance
      1. Multiple inheritance
      2. Multilevel inheritance
    6. Overriding methods
    7. Operator overloading
    8. The class method
    9. The static method
    10. The private variable
    11. Summary