First Python Program :
#Basic Syntax and Variable types in Python.
Type the following text at the python prompt and press the enter:
|>>> print(” Hello world”)|
Now if you run the program you get the Output as follows:
A python identifier is a name to indentify a variable, function, class, module, or other objects. An identifier starts with a letter A to Z or a to z, or an underscore(_) followed by zero or more letters l, underscores and digits(0-9).
Python does not allows punctuation characters such as @, $ and % within identifiers, Python is case sensitive programming language. Thus, Mechomotive and Mechomotive are two different identifiers in python.
Lines and indentation
Python uses line indentation to indicate class, function definitions or flow control.
The number of spaces in the indentation is variable though all statements within the block must be indented the same amount. For example:
print (” True”)
print (” False”)
Thus, in Python all the continuous lines indented with same number of spaces would form a block.
Quotation in python
Python accepts single(‘), double(“) and triple(‘ ‘ ‘ or ” ” “) quotes to denote string literals, as long as the same type of qoute starts and ends the string.
|word = ‘ Mechomotive’|
Sentence = ” This is Mechomotive”
Paragraph = “”” Mechomotive is a learning platform “””
Comments in python
A hash sign (#) that is not inside a string literal begins a comment. All characters after the # and up to the end of the physical line are part of the comment and the python interpreter ignores them.
|# First comment|
print( ” Hello, Mechomotive! “) # second comment
This produce the following result:
You can type a comment on the same line after a statement or expression :
|Name = ” Mechomotive” #This is again comment|
Basic Syntax and Variable types in Python.