Python Basic syntax, Indentation, Reserved Words, Naming Conventions
Basic syntax
print():-
The print() function prints the specified message to the screen, or other standard output device.
Example
>>>print("Hello World")
Output
Hello World
Note:- This code save with a .py for example first.py .
Indentation
Python indentation is a way of telling a python interpreter that the group of statement
belong to particular block of code.
A block is a combination of all these statements. Block can be regarded as the grouping of statements for a specific purpose. Most of the programming languages like C, C++, Java use braces { } to define a block of code. Python uses indentation to highlight the blocks of code. Whitespace is used for indentation in Python. All statements with the same distance to the right belong to the same block of code. If a block has to be more deeply nested, it is simply indented further to the right. You can understand it better by looking at the following lines of code.
Example
# Python program showing
# indentation
site = 'agency analytics'
if site == 'agency analytics':
print('Logging on to agency analytics..')
else:
print('retype the URL.')
print('All set !')
Output:
Logging on to agency analytics..
All set !
Reserved Words
Reserved words (also called keywords) are defined with predefined meaning and syntax in the language. These keywords have to be used to develop programming instructions. Reserved words can’t be used as identifiers for other programming elements like name of variable, function etc.
Following is the list of reserved keywords in Python 3
and | except | lambda | with |
as | finally | nonlocal | while |
assert | false | None | yield |
break | for | not | |
class | from | or | |
continue | global | pass | |
def | if | raise | |
del | import | return | |
elif | in | True | |
else | is | try |
Naming Conventions
There are certain rules we need to follow while naming a function in Python.
Rule-1: You should start variable name with an alphabet or underscore(_) character.
Rule-2: A variable name can only contain A-Z,a-z,0-9 and underscore(_).
Rule-3: You cannot start the variable name with a number.
Rule-4: You cannot use special characters with the variable name such as such as $,%,#,&,@.-,^ etc.
Rule-5: Variable names are case sensitive. For example str and Str are two different variables.
Rule-6: Do not use reserve keyword as a variable name for example keywords like class, for, def, del, is, else, try, from, etc.
Previous Next
Tags
Python Tutorial