What is Program? As we know that Program is a set of instructions which perform a particular task. Now, you can write these instructions with the help of tokens, letters, digits, special symbols, white spaces and other characters. We use these 1000 of times, but you know that all comes under CHARACTER SETS? Now, your mind striking more about Character sets, that what is Character Sets in Python? Are these available only in Python?
Just relax, you will find all your answers about Characters Set in these articles. In this article you will read about :
- Character Sets
- Token
- Keywords
- Literals
- Operators
- Punctuators
Let’s Start with Character Sets :
- Character set is a bunch of identifying elements in the programming language.
- Character set is a set of valid characters that a language can easily recognize.
- So, whenever we write anything in python it must be a character or a set of characters so that Python understands it easily.
- A character set consists of the followings
Tokens in Python :
- The smallest individual unit in a program is known as a Token or a Lexical Units.
- Python has following tokens:
Keywords :
- Keywords are the reserved words used by Python interpreter to recognize the structure of a program.
- Due to their specific meaning for interpreter, they cannot be used as variable names or for any other purpose.
- All keywords are in lower case except False, True and None which starts from a capital alphabets.
- If you want to see all keywords, then simply type “help()” in python shell and after that write “keywords”.
- There are total 35 keywords in python. They are:
Identifiers:
- An identifier is a name used to identify a variable, function, class, module or other object.
- Rules of creating identifiers :
- Identifier name must start with an alphabet (capital or small).
- An identifier must not be a keyword.
- An identifier cannot contain any special character except for underscore(_)
- An identifier cannot be start with digit, however digits can be part of it.
- Upper case and lower case letter are different i.e. Name, name and NAME are different.
Literals:
- Basically, literals are a notation for representing a fixed value in source code. They can also be defined as raw value or data given in variables or constants.
- Python allows several kinds of literals:
String Literals :
- A string literal is a sequence of characters surrounded by quotes (single or double or triple quotes). By using triple quotes we can write multi-line strings or display in the desired way.
- Example :
Numeric Literals :
There are 3 types of numeric literals, i.e.
- Integer
- Float
- Complex
Integer :
- Both positive and negative numbers including 0.
- There should not be any fractional part.
- A number with no sign is assumed to be positive.
- Commas cannot appears in an integer constant.
- Python allows three types of integer literals :
Decimal Integer Literals.
Octal Integer Literals.
Hexadecimal Integer Literals.
Float :
These are real numbers having both integer and fractional parts.
Complex Literals :
The numerals will be in the form of a+bj, where ‘a‘ is the real part and ‘b‘ is the complex part.
Boolean Literals :
There are only two Boolean literals in Python. They are True and False.
Special Literals :
- Python contains one special literal (None). ‘None’ is used to define a null variable. If ‘None’ is compared with anything else other than a ‘None’, it will return false.
- The None value in Python means “There is no useful information” or “There is nothing here”.
Literal Collections:
There are four different types of literal collections
- List literals
- Tuple literals
- Dict literals
- Set literals
Operators
- Operators are tokens that trigger some computation/action when applied to variables and other objects in an expression.
- Variables and objects to which the computation is applied, are called operands. So, we can say that operator requires some operands to work upon.
- Python supports Unary and Binary Operators
Punctuators
- Punctuators are the symbols that are used in python to organize programming-sentence structures, and indicate the rhythm and emphasis of expressions, statements, and program structure.
- Most common punctuators of Python are:
‘ “ # \ ( ) [ ] { } @ , : . ` =
1 comment
Nice article