Tuesday, November 19, 2019

Python Fundamentals.

Python Character Set :

  • It is a set of valid characters that a language recognize.
  • Letters: A-Z, a-z
  • Digits : 0-9
  • Special Symbols
  • White space

Tokens

Token: Smallest individual unit in a program is known as token.
There are five types of token in python:
1. Keyword
2. Identifier
3. Literal
4. Operators
5. Punctuators

1. Keyword: 


  • Reserved words in the library of a language. 
  • There are 33 keywords in python.

  • All the keywords are in lowercase except 03 keywords (True, False, None).

2. Identifier: 

  • The name given by the user to the entities like variable name, class-name, function-name etc.

Rules for identifiers: 

  • It can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore.
  • It cannot start with a digit.
  • Keywords cannot be used as an identifier.
  • We cannot use special symbols like !, @, #, $, %, + etc. in identifier.
  • _ (underscore) can be used in identifier.
  • Commas or blank spaces are not allowed within an identifier. 

3. Literal: 

  • Literals are the constant value. Literals can be defined as a data that is given in a variable or constant.

A. Numeric literals: Numeric Literals are immutable. Eg. 5, 6.7, 6+9j
B. String literals: String literals can be formed by enclosing a text in the quotes. We can use both single as well as double quotes for a String. Eg: "Aman" , '12345'

  • Escape sequence characters:


C. Boolean literal: A Boolean literal can have any of the two values: True or False.
D. Special literals: Python contains one special literal i.e. None. 
None is used to specify to that field that is not created. It is also used for end of lists in Python. 
E. Literal Collections: Collections such as tuples, lists and Dictionary are used in Python.

4. Operators: 

  • An operator performs the operation on operands. Basically there are two types of operators in python according to number of operands:

A. Unary Operator
B. Binary Operator
A. Unary Operator: Performs the operation on one operands.

Example:

+ Unary plus
- Unary minus
~ Bitwise complement
not Logical negation

B. Binary Operator: Performs operation on two operands.

5. Separator or punctuator :

      , ; , ( ), { }, [ ]
2.3 Mantissa and Exponent Form:
A real number in exponent form has two parts:
  • mantissa
  • exponent

Mantissa : It must be either an integer or a proper real constant.
Exponent : It must be an integer. Represented by a letter E or e followed by integer value.






1 comment:
Write comments