Python language is designed simple in terms of its syntax. Syntax is the set of rules, principles that define the structure of the programing language. There are many similarities between other programming languages like C, C++, Java and Python.
What is the Mandatory Python Syntax that must be followed by every coder?
Some rules must be followed while writing the Python code. They are:
- Case-sensitive: As we know Python is a case-sensitive language so we must take care while declaring and using object name to avoid the errors. The variable “first_name” and “First_name” are different.
- Forward slash (/): Python uses forward slash for path specification. An as windows file path has backward slash, you have to convert to forward slash.
Windows “C:\go coding\” should be converted to “C:/go coding/”.
- The executable statement must be written in a single line as the line change will act as the terminator.
- To write two executable statements in a single line use a semicolon after one executable statement and then write the second statement.
- Strings can be enclosed either by single quotes ‘ ‘ or double quotes “ “ or triple quotes “”” ‘’’.
- Hashtag (#) is used at the start of the line for comments in the program.
- You can use backslash (\) at the end of the line for line continuation.
sum = 2 + \
Namespace in Python (only brief, as we have individual topic for this)
Namespace are the unique names given to each objects in Python programme. Let us consider one real-time example, suppose there are three students of same name “Ram Kumar” in different streams of engineering college. Now how people will find one particular “Ram Kumar”. They have to provide the particular stream to search for the desired person. Here the stream works as the namespace.
Similarly, Python interpreter which variable or method is being pointed depending upon the namespaces.
Types of namespaces:
- Local namespaces
- Global namespaces
- Built-in namespaces
Keywords in Python
Keywords are the reserved words holding special meaning in programming language. These words cannot be used for naming variables, constants and any other identifiers.
Below is the list of keyword in Python:
NOTE: Except True, False and None all other keywords are in lower-case.