Your ultimate guide

Identifiers and Reserved keyword in Python

Identifiers:
    A name in a Python program is called Identifier. It can be a class name or function name or module name or variable name.

    1. The only allowed characters in Python are
Alphabet (either lower case or upper case)
- digits (0-9)
- underscore symbol (_)
- num =10 ✅
first_num = 10 
- first$num = 10 ❌

    2. Identifier should not start with the digit
12sum 
sum12 
_sum_12 

    3. Identifiers are case-sensitive.
Num = 10
num = 20
print(Num) # 10
print(num) # 20

Reserved Keyword:
    In Python, some words are reserved to represent some meaning or functionality. such types of words are called Reserved words.

There are 35 reserved words available in Python

and as assert async await break class
continue def del elif else except finally
for from global if import in is
lambda nonlocal not or pass raise return
try while with yield True False None

Note: Except for the 3 reserved words True, False, and None, all contain only lowercase alphabet symbols.


>>import keyword
>>keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']


Python Comments:
    Comments in Python are the inclusion of short descriptions along with the code to increase its readability. when we mention comments in the code Python will ignore them.
    1. Single Line Comments:
        Comments start with a "#".
        Example:
        >>>print("Hello, World")  #This is a comment
    2. Multiline Comments:
        Python does not really have a syntax for multiline comments. To add the multiline comment you could insert "#" for each line.
        Example:
        >>>#This is a comment
        >>>#To print Hello world
        >>>#written by TestingColleges
        >>>print("Hello, World")

    Python will ignore string literals that are not assigned to a variable, you can add the multiline string in triple quotes(" " " / ' ' ') in your code, and place your comment inside it.
        Example:
        >>>" " " 
        This is a comment
        To print Hello World
        Written by TestingColleges
        " " "
        >>>print("Hello, World")

No comments:

Post a Comment