Python Tokens and Comments
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
a python identifier is a name used to identify a variable, function, class, module, or other objects. Ex: MyBook, myBook, mybook, etc.
- Literals
Literals in Python can be defined as numbers, text, or other data that represent values 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
- 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 z or an underscore (_) followed by zero or more letters, underscores, and digits (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
And | Assert | Break |
class | Continue | def |
del | elif | else |
except | exec | finally |
for | from | global |
if | import | in |
is | lambda | Not |
or | pass | |
raise | return | try |
while | with | yeild |
Python | Punctutors
![punctuators](https://www.csharp.com/UploadFile/Tutorial/2151b8/37/images/20200706042743/python_punctuators.png)
Python | Comments
Single-Line Comments
- # So let's Print Something- Comment 1
- print “A chunk of text!” # Print- Comment2
Multiline Comments
- “””
- 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.
Author
Abhishek Jaiswal
95
19.8k
9.6m