Introduction
In this chapter, we will discuss python tokens and Python comments.
Python Character Set
The following are then character set recognized by python. It uses the traditional ASCII character set.
- Letters
A-Z, a-z
- Digits
0-9
- Special Symbols
Special Symbols available over Keyboard (some of the symbols like rupee symbol may not be available)
- White Spaces
blank space, tab, carriage return, newline, form feed
- Other Characters
Unicode
Python Tokens
The smallest individual unit in a program is known as a token.
- Keywords
There are in total of 31 reserved keywords. Ex: and, finally, not, etc.
- Identifiers
apython identifier is a name used to identify a variable, function,class, module, or other objects. Ex: MyBook, myBook, mybook, etc.
- Literals
Literalsin Python can be defined as numbers, text, or other data that representvalues to be stored in variables. Ex: age = 22, escape sequence, etc.
- Operators
It can be defined as symbols that are used to perform operations on operands. Ex: arithmetic operators, etc.
- Punctuators
Used to implement the grammatical and structure of a Syntax. Ex: &=, >>=, <<=, etc.
Python | Identifiers
An identifier, in general, programming terms they can be defined as in the following,
"A name that can be used for identifying a variable, function, class, object, name, and so on in a program, is called an Identifier."
This same definition and concept applies also to Python.
Here are some basic details one needs to understand about Python identifiers (common),
- Must start with upper case (A … Z) or lowercase (a … z) letters
- It can be also started with an underscore "_", followed by more letters
- It can also be the combination of underscore and numbers
PinPoints
- Since Python is a case sensitive programming language, "Abhishek" and "abhishek" are different things for it.
- Python doesn't allow you to use some special characters (@, #, $, %) in your identifier name.
- Class names start with an uppercase letter followed by the lowercase.
Rules to define Python Identifiers
- An identifier starts with a letter A to Z or a to zor an underscore (_) followed by zero or more letters, underscores, anddigits (0 to 9).
- Python does not allow special characters
- An identifier must not be a keyword of Python.
- Python is a case sensitive programming language.
- Class names start with an uppercase letter. All other identifiers start with a lowercase letter.
- Starting an identifier with a single leading underscore indicates that the identifier is private.
- Starting an identifier with two leading underscores indicates a strongly private identifier.
- If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.
Python | Keywords
A keyword, in general, programming terms can be defined as,
"These are reserved words that are already used in language for defining some special tasks or functionalities and you can't use them as a constant or variable name in your code.
Let's quickly have a look at those.
And | Assert | Break |
class | Continue | def |
del | elif | else |
except | exec | finally |
for | from | global |
if | import | in |
is | lambda | Not |
or | pass | print |
raise | return | try |
while | with | yeild |
Python | Comments
Single-Line Comments
In Python, a line that starts with a hash "#" is considered to be a comment by the Python interpreter.
So write comments and enjoy Python, write as much as you can but in a limit and trust me it will help you too. How? It will make your code more understandable, readable and it also considered as one of the guidelines of programming. So cheers.
Have a look at the following snippet.
Multiline Comments
No worries, if you want a multiline comment in Python. You can easily do that using this structure:
“””
Your comments go here…
“””
For Example - “””
-
- This is my multiline comment in Python...
-
- “””
-
- print “A chunk of text!”
Conclusion
In the next chapter, we will learn how we can install python on various operating systems.