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

Introduction to Python 2018 Edition

Book Description

Few programming languages provide you with the flexibility and pure power of Python.

If you're becoming a professional developer, or are early in your development career, adding the Python skill set isn't just a resume embellishment-- It's an empowering language that will allow you to write procedural code in many types of environments and for many uses.


Python is commonly used for server side programming for complex web applications or as a middle tier language providing web services or a communication layer with larger ecommerce systems. That being said, it's also a great language for beginners. The clear syntax makes it very easy to learn, and the powerful libraries make all types of programming possible. There are libraries for everything from games and graphics to complex mathematics to network and embedded programming.

Watch, Learn and Do

Programming is not a spectator sport and if you want to learn Python well, this book contains everything you need.

You'll be able to study and modify the code provided on your own to cement each topic. Python code coding lab exercises will familiarize you not just with Python syntax, but how real problem-solving in Python is done.

Table of Contents

  1. Title Page
    1. Copyright Page
    2. Dedication
  2. Chapter 1 – Introduction
    1. Intended Audience
    2. What Does the Book Cover?
    3. Important Things to Remember
  3. Chapter 2 – Getting Started
    1. Downloading and Installing Python
    2. Running IDLE
    3. Writing Your First Python Program
    4. Running the Program
    5. Editing your First Program
    6. Using the Shell Window
    7. To Change the Editor’s Various Font-Related Features
    8. To Change the Editor’s Highlighted Text Colors
    9. To Use the Shell in Interactive Mode
    10. Writing Code in the Editor Window
    11. Executing Python on the Command Line
    12. Coding Exercise: Writing, Running and Debugging
  4. Chapter 3 – Output
    1. The print() Function
    2. Separators and Newlines
    3. Coding Exercise: Using the print() Function
  5. Chapter 4 – Variables
    1. Variable Assignment
    2. Number Variables (int , float, and complex)
    3. String Variables
    4. Substrings and Concatenation
    5. Variables with Lists, Tuples, and Dictionaries
    6. Coding Exercise: Using Variables
  6. Chapter 5 – Operators
    1. Mathematical Operators
    2. Order of Operations
    3. Comparison Operators
    4. Logical Operators
    5. Coding Exercise: Operators Practice
    6. Chapter 6 – Code Branching
    7. Simple If Statements
    8. If...Else Statements
    9. Nested If Statements
    10. The Ternary Operator
    11. Coding Exercise: Operators Practice
  7. Chapter 7 – Loops
    1. The While Loop
    2. The For Loop
    3. Nested Loops
    4. Break and Continue Statements
    5. Coding Exercise: Loops
  8. Chapter 8 – Math Functions
    1. Casting Functions
    2. Mathematical Functions
    3. Random Functions
    4. Coding Exercise: Math Functions
  9. Chapter 9 – String Functions
    1. The capitalize (), center (), and count () functions
    2. The find (), isalpha (), and isdigit () functions
    3. The join (), len (), and split () functions
    4. Coding Exercise: String Functions
    5. Chapter 10 – Tuples and Dictionaries
    6. Creating Tuples
    7. Accessing Values in Tuples
    8. Printing specific values from a tuple
    9. Looping through a Tuple
    10. Tuple Functions
    11. What are lists?
    12. The len() Function
    13. Using the len() Function to Loop through a Tuple
    14. The min() and max() Functions
    15. Converting a List to a Tuple
    16. Declaring a Dictionary
    17. Accessing and Editing Values in Dictionaries
    18. Printing specific values from a dictionary
    19. Changing the elements in a dictionary
    20. print(“Change:”, player[“Position”])
    21. Deleting an element in a dictionary
    22. Dictionary Functions
    23. The len() Function
    24. The str() Function
    25. The clear() Function
    26. The get function
    27. The items function
    28. The values function
    29. The keys function
    30. Getting the Elements and Key-Value Pairs in a Dictionary
    31. Coding Exercise: String Functions
  10. Chapter 11 – Time and Date
    1. The Time Tuple
    2. time.asctime(time.localtime(time.time()))
    3. The Calendar
    4. The Time and Calendar Functions
    5. Coding Exercise: Functions
  11. Chapter 12 – Python Functions
    1. Defining and Calling a Simple Function
    2. Required Argument Functions
    3. Keyword Argument Functions
    4. Default Function Arguments
    5. Return Statement
    6. Creating and Consuming Python Modules
    7. Coding Exercise: Functions
    8. Chapter 13 – Input and Output
    9. Reading Keyboard Input
    10. Reading an External Text File
    11. Writing an External Text File
    12. Coding Exercise: File I/O
  12. Chapter 14 – More with Python
    1. Handling Exceptions
    2. Web Server Coding with Python
    3. Processing Form Data with Python
    4. Wrap Up and Goodbye
  13. About the Author