Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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
Python Essentials

You're reading from   Python Essentials Modernize existing Python code and plan code migrations to Python using this definitive guide

Arrow left icon
Product type Paperback
Published in Jun 2015
Publisher Packt
ISBN-13 9781784390341
Length 298 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Steven F. Lott Steven F. Lott
Author Profile Icon Steven F. Lott
Steven F. Lott
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Getting Started FREE CHAPTER 2. Simple Data Types 3. Expressions and Output 4. Variables, Assignment and Scoping Rules 5. Logic, Comparisons, and Conditions 6. More Complex Data Types 7. Basic Function Definitions 8. More Advanced Functions 9. Exceptions 10. Files, Databases, Networks, and Contexts 11. Class Definitions 12. Scripts, Modules, Packages, Libraries, and Applications 13. Metaprogramming and Decorators 14. Fit and Finish – Unit Testing, Packaging, and Documentation 15. Next Steps Index

Examining syntax rules

There are nine fundamental syntax rules in section 2.1 of the Python Language Reference. We'll summarize those rules here:

  1. There are two species of statements: simple and compound. Simple statements must be complete on a single logical line. A compound statement starts with a single logical line and must contain indented statements. The initial clause of a compound statement ends with a : character. It's possible, using rules 5 and 6, to join a number of physical lines together to create a single logical line.
    • Here's a typical simple statement, complete in a single logical line:
      from decimal import Decimal
    • Here's a typical compound statement with a nested simple statement, spread across two logical lines:
      if a > b:
          print(a, "is larger")
  2. A physical line ends with \n. In Windows, \r\n is also accepted.
  3. A comment starts with # and continues to the end of the physical line. It will end the logical line.
    • Here's an example of a comment...
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 $19.99/month. Cancel anytime
Banner background image