Python

<< Click to Display Table of Contents >>

Navigation:  Scriptiing >

Python

Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.

The one new syntax component in Python is the colon character (:). All Python compound statements—statements that have other statements nested inside them—follow the same general pattern of a header line terminated in a colon, followed by a nested block of code usually indented underneath the header line

Header line:

 Nested statement block

The colon at the end of the header line is required.

 

You don’t need to terminate statements with semicolons in Python the way you do in C-like languages. The general rule is that the end of a line automatically terminates the statement that appears on that line.

 

You do not type anything explicit in your code to mark the beginning and end of a nested block of code. Instead, you need to consistently indent all the statements in a given single nested block the same distance to the right, and Python uses the statements’ physical indentation to determine where the block starts and stops. e.g.

if x > y:

 x = 1

 y = 2

 

Python doesn’t care how you indent (you may use either spaces or tabs), or how much you indent (you may use any number of spaces or tabs).

 

Control Statement