Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learn Web Development with Python

You're reading from   Learn Web Development with Python Get hands-on with Python Programming and Django web development

Arrow left icon
Product type Course
Published in Dec 2018
Publisher
ISBN-13 9781789953299
Length 796 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Fabrizio Romano Fabrizio Romano
Author Profile Icon Fabrizio Romano
Fabrizio Romano
Gaston C. Hillar Gaston C. Hillar
Author Profile Icon Gaston C. Hillar
Gaston C. Hillar
Arun Ravindran Arun Ravindran
Author Profile Icon Arun Ravindran
Arun Ravindran
Arrow right icon
View More author details
Toc

Table of Contents (33) Chapters Close

Title Page
About Packt
Contributors
Preface
1. A Gentle Introduction to Python FREE CHAPTER 2. Built-in Data Types 3. Iterating and Making Decisions 4. Functions, the Building Blocks of Code 5. Saving Time and Memory 6. OOP, Decorators, and Iterators 7. Files and Data Persistence 8. Testing, Profiling, and Dealing with Exceptions 9. Concurrent Execution 10. Debugging and Troubleshooting 11. Installing the Required Software and Tools 12. Working with Models, Migrations, Serialization, and Deserialization 13. Creating API Views 14. Using Generalized Behavior from the APIView Class 15. Understanding and Customizing the Browsable API Feature 16. Using Constraints, Filtering, Searching, Ordering, and Pagination 17. Securing the API with Authentication and Permissions 18. Applying Throttling Rules and Versioning Management 19. Automating Tests 20. Solutions 21. Templates 22. Admin Interface 23. Forms 24. Security 25. Working Asynchronously 26. Creating APIs 27. Production-Ready 1. Other Books You May Enjoy Index

Conditional programming


Conditional programming, or branching, is something you do every day, every moment. It's about evaluating conditions: if the light is green, then I can cross; if it's raining, then I'm taking the umbrella; and if I'm late for work, then I'll call my manager.

The main tool is the if statement, which comes in different forms and colors, but basically it evaluates an expression and, based on the result, chooses which part of the code to execute. As usual, let's look at an example:

# conditional.1.py
late = True 
if late: 
    print('I need to call my manager!') 

This is possibly the simplest example: when fed to the if statement, late acts as a conditional expression, which is evaluated in a Boolean context (exactly like if we were calling bool(late)). If the result of the evaluation is True, then we enter the body of the code immediately after the if statement. Notice that the print instruction is indented: this means it belongs to a scope defined by the if clause. Execution...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime