Introduction
In this article, we learn some fundamentals of Python, like Identifiers, Reserved words, Comments, Multiline Statement, Quotation in python, Multiple statement in single line, Suites, etc.
Python Identifiers
Python Identifiers are smaller elements of a Python program. We can say that Identifiers are the name used to identify a variable, module, class, function, and other objects.
Rule for Identifiers
- Python Identifiers are stared with alphabet (a-z) or(A -Z) Or underscore ( _ )
- Python Identifiers are followed by any alphabet (a-z) or (A-Z) , number (0-9) and underscore(_)
- Python Identifiers does not start with digit(number (0-9)) and any special characters( @,% and $ etc.)
- Python Identifiers does not have any special characters (@,% and $ etc.)
Example
Identifiers name
|
Correct or incorrect
|
_name
|
Correct
|
_name1
|
Correct
|
name_
|
Correct
|
2name
|
Incorrect
|
name_lastname_1
|
Correct
|
@name
|
Incorrect
|
name@
|
Incorrect
|
Name
|
Correct
|
Name1
|
Correct
|
Python is case sensitive language. For example, in Python, CSHAPCORNER and csharpcorner both are different Identifiers (Shown in the picture below).
Names for Identifiers in Python
- In Python, class names should be started with an upper letter.
- Starting with an underscore means the identifier is private.
Python reserved word (key word)
Python keywords (reserved words) are words which is reserved by the Python and we cannot use as variables and constraints
Python keywords are listed below:
Python reserved words
|
False
|
True
|
from
|
if
|
None
|
def
|
global
|
import
|
And
|
del
|
raise
|
in
|
As
|
elif
|
return
|
is
|
Assert
|
else
|
try
|
lambda
|
Break
|
except
|
while
|
nonlocal
|
Class
|
finally
|
with
|
not
|
Continue
|
for
|
yield
|
or
|
Pass
|
Pass
|
Pass
|
Pass
|
Comments in Python
- Python also supports comments like other programming languages.
- All characters and strings after the hash (#) sign and before finishing the physical line
- Python does not support multiline comments.
Example
-
- print("this is c#corner python tutorial by ajay malik")
-
Output
In the above example, the comment is ignored by Python.
Line and Indentation
In Python, no braces exist to indicate the block of a function, class and code. It is indicated by line indentation.
For example:
Quotations in Python
Python supports single (‘), double (“) and triple (‘’’ or “””) quotes to denote a string.
Triple (‘’’ or “””) are used to span strings in multiple lines.
For example:
- name = 'Python'
- type = "programming language"
- content = """Python is an open-source programming language
free to download and easy to use"""