Python Programming – Simple and Compound Statements

In this Page, We are Providing Python Programming – Simple and Compound Statements. Students can visit for more Detail and Explanation of Python Handwritten Notes Pdf.

Python Programming – Simple and Compound Statements

A statement is a unit of code that the Python interpreter can execute. A script usually contains a sequence of statements.

A namespace is a logical grouping of the objects used within a program. Most namespaces are currently implemented as Python dictionaries. Examples of namespaces are the set of built-in names (containing functions such as abs ( ), and built-in exception names), the global names in a module, and the local names in a function definition.

The important thing to know about namespace is that there is absolutely no relation between names in different namespaces. For instance, the functions ____built-in______.open ( ) and os . open ( ) are distinguished by their namespaces. The following is an example of the local namespace.

>>> def example ( arg ) :
. . .       x=4
. . .       print locals ( )
. . . 
>>> example ( 10 )
{ ' x ' : 4 , ' arg ' : 10 }
>>> example ( ' hello ' )
{ ' x ' : 4 , ' arg ' : ' hello ' }

The function example ( ) has two variables in its local namespace: arg, whose value is passed into the function, and x, which is defined within the function. The locals ( ) built-in function return a dictionary of name-value pairs; the keys of this dictionary are the names of local variables as strings; the values of the dictionary are the actual values of the variables.