Python – Learn from Basic to Advanced
Python: Programming Fundamentals
Python Character Set:
A python program is a sequence of character. A character can represent any letter, digit, or any other sign.
Following are some of the python character set.
LETTERS
DIGITS
SPECIAL SYMBOLS
WHITE SPACE
OTHER CHARACTERS
A to Z and a to z
0 -9
Space, + -* ^ \ [] {} =! = < > . ‗ ‗ ; : & #, under score(_) etc.
Blank space, horizontal tab ( - > ), carriage return , Newline, Form feed.
Python can process all ASCII and Unicode characters as part of data or literals.
Whene these characters are submitted to the python interpreter, they are interpreted in various contex as characters, names/ identifiers, constants and ststements.
Python: Tokens
Python break each logical line into sequence of elementary lexical components known as token.
OR
The smallest individual unit in a program is known as token or lexical unit.
​
The types of tokens are given as follows:
1) Keywords:
Keywords are special identifiers with predefined meanings that cannot change. As these words have specific meaning for interpreter, they cannot be used for any other purpose.
​
Some Commonly Used Keywords:
Note:
-
They must be be spelled exactly as they are written.
-
Keywords can not be used as name or identifiers in the program.
2) Identifiers:
Identifiers are names given to identify something. Identifiers are fundamental building blocks of a program and are used as general terminology for the names given to a different part of the program that is variables, objects, classes, functions, lists, dictionaries etc.
NOTE: An identifier must not be a keyword of Python
There are some rules you have to follow for naming 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.
Thus, Sname and sname are two different identifiers in Python.
Some valid identifiers: Mybook, file123, z2td, date_2, _no
Some invalid identifier:
Some invalid variable name which produces syntax errors are as
SyntaxError: invalid syntax because variable start with a digit
SyntaxError: invalid syntax because variable contains space
SyntaxError: invalid syntax because variable is a reserve word
SyntaxError: invalid syntax because variable contains a special character
>>> 98Sep_sco
>>> myname@
>>> Your Age
>>> while
3) Literals / Values:
Literals in Python can be defined as number, text, or other data that represent values to be stored in variables. The data items which never change their value throughout the program run. There are several kinds of literals:
-
String Literals
-
Numeric Literals
-
Boolean Literals
-
Special Literal None
-
Literal Collections
4) Delimiters:
Delimiters are used to implement the grammatical and structure of Syntax.
Delimiters are used in various areas of the Python language. They are used to build expressions, string literals, tuples, dictionaries or lists.
Following are the python delimiters.
Classification
Delimiters
Grouping
Punctuation
Bit-wise Assignment
Arithmetic Assignment
( ) [ ] { }
& | ~ ^ << >>
+ - * / // % **
. , ; @ ' " / #
5) Operators:
Operators are special symbols that perform specific operations on one, two, or three operands, and then return a result.
Operators Types
Grouping
Arithmetic
Relational
Operators
( ) [ ] { }
+ - * / // % **
Logical
and or not
Bit-wise
& | ~ ^ << >>
== != < > <= >= is in