
Python Identifiers
- letter A to Z
- letter a to z
- underscores(_)
- it should start with (one or more characters) or (an underscore) then use digits (0 to 9).
- var1
- _var1
- _1_var
- var_1
- Var1
- ___1var
- $var1
- 2var
- 1_var
- var'Hash1
Python is a case-sensitive language. This means Var and var are not the same, A and a are not the same these two are different. Always give the identifiers name which makes sense. c = 10 is a valid name but if you write count = 10 that makes more sense, and it would be easier to find out what it represents when you look at your code after a long gap/time.
Multiple words can be separated using an underscore, like First_Name
Keywords
Python keywords are reserved words that we cannot use as static or variable or any other identifier name. all the keywords are always is in lowercase letters, it is restricted.
The following list shows the Python keywords.
- and
- exec
- not
- assert
- finally
- or
- break
- for
- pass
- class
- from
- continue
- global
- raise
- def
- if
- return
- del
- import
- try
- elif
- in
- while
- else
- is
- with
- except
- lambda
- yield
Python Indentation
Indentation means the spaces at the starting of a code line. In other programming languages, the indentation in the code is only for readability, in Python the indentation is very important.
- Python uses indentation to represent a block of code, as shown in the example below
>>>if(10>2):
print("10 is greater than 2")
Output:-
10 is greater than 2
Indentation in Python Shell
- If you skip the indentation, Python will give you an error:
>>>if(10>2):print("10 is greater than 2")

- The number of spaces depends on you as a programmer, but it must be at least one.
>>>if(10>2):print("10 is greater than 2")else:print("10 is smaller than 2")

- You need to use the same number of spaces in the same block of code, if not Python will give you an error:
>>>if(10>2):print("10 is greater than 2")print("2 is smaller than 10")
Creating a Comment
- Comments start with a hash mark, and the Python will ignore them:
'hash This is a commentprint("Welcome to the Technogyyan!")
Comment in python shell.
- Comments can be located at the end of the line and Python ignores the rest of the lines:
print("Welcome to the Technogyyan!") 'hash This is a comment
comment at the end of the line in Python shell.
Multiline Comment
- You can add a 'hash for each line to add a multi-line comment:
'hash This is a comment'hash written in'hash more than just one lineprint("Welcome to the Technogyyan!")
Multiline comment(Using 'hash) in Python shell.
Python will ignore non-assigned string literals to the variable.
- You can add a multiline string in triple quotes(""") to your code and leave your comment in it:
"""
This is a comment
written in
more than just one line
"""
print("Welcome to the Technogyyan!")
Multiline comment(triple quotes) in Python shell.
Amazing tutorials on Python. Learning and practicing data structures and algorithms in Python is essential to develop solid problems solving skills. I appreciate your efforts in writing this amazing article. Thank you for sharing this.
ReplyDeletePost a Comment