Elements of Python


  • A name in python programming is called Identifier.
  • It can be a variable name, function name, class name, and module name.
  • Identifier refers to the name given to entities such as variables, functions, class, etc.

Example:   a=10   # ‘a’ is a variable name
Sum(a,b) # calling function

Rules for Identifiers:

  • Name contains alphabet symbols(both upper and lower case), digits(0—9), ‘_’ underscore.
  • Ex: man, easy2share, back_to_back
  • The name should starts with Alphabet or underscore but not digits.
  • Ex: total123 –> Valid
    2morrow –> Invalid
  • Identifiers are case sensitive. Of course, Python language is case sensitive programming language.
  • Ex: total = 10
    TOTAL = 99
    Print(total) # 10
    Print(TOTAL) # 99
  • Keywords are not used as identifier.
  • Ex: if, else, for –> Invalid
  • White spaces and special characters are not allowed.
  • Ex: Man power –> Invalid
    Ca$h –> Invalid
  • There is no limit on the length of a variable name.
    1. Ex: giveanynamewithmorenumberofcharacter –>valid
      Man_power –> valid
      Net pay –> Invalid
      Ca$h –> Invalid
      2morrow –> Invalid
      _net_pay_ –> Valid
      if –> Invalid
      easy2share –> Valid


  • Keywords are also known as Reserve words, they have predefined meaning in Python and these words cannot be changed by the user.
  • Keywords contain only alphabet symbols.
  • All keywords are lower case except the following three keywords.

  • True, False, None
  • There are 33 reserved words are there in Python

  • True, False, None
  • and,or,not,is
  • if,elif,else
  • while,for,break,continue,return,in,yield
  • try,except,raise,finally,assert
  • import, from, as,class,def,pass,global,nonlocal,lamda,del,with

Data Types:

  • Data type represents the type of data present inside a variable. or
  • Data types represent a kind of value that determines what operations can be performed on that data.
  • Numeric, non-numeric, and Boolean (True/False) data are the most used data types.

Types of Data Type:

  1. Fundamental Data Types:
    int, float, complex, bool, and str
  2. Collection related Data Types:
    list, tuple, set, frozenset, bytes, bytesarray, range, and dict

1.Fundamental Data types:

  • There are 5 fundamental data types, these data types are also known as inbuilt data types.
    1. int
    2. float
    3. complex
    4. bool
    5. str (string)


  • This data type holds or stores an only integer value.
  • To represents only integral values without decimal point then we can use int data type.
    • Ex: a=10, –>   don’t need to declare data type explicitly, based on provided value it will assign data type, this is called dynamically typed programming language.  
    • Type(a) –> int.  
  • In python-3 ‘long’ data type is not available.
  • For all values like short value, medium, and large value we can int data type only.
  • Python Provides some inbuilt functions.
  • print() –> To display values stored in variables
  • type() –> To Know the type of the data stored in a variable
  • id()      –> To know the address of the variable
    • Ex:   a= 10
    • Print(a) # 10
    • type(a) # <class ‘int’>
    • id(a) # ‘68919472’
  • The integer value is represented in four ways.
    1. Decimal Form (base-10):
      –>Ex: a=20, a=7878, etc.
    2. Binary Form (base-2):
      –>Ex: a=0b1111 –> 15 in Decimal, a = 0B1010 –> 10 in Decimal
    3. Octal Form (base-8):
      –>Ex: a= 0o15 –> 13 in Decimal, a = 0o77 –> 63 in Decimal
    4. HexaDecimal Form (base-16):
      –>Ex: m= 0Xf –> 15 in Decimal, M = 0Xface –> 64206 in Decimal

2.Floating-Point Numbers:

  • The float type in Python designates a floating-point number. float values are specified with a decimal point.
  • Floats may also be in scientific notation, with E or e indicating the power of 10 (2.5e2 = 2.5 x 102 = 250).
  • Using an exponential form, we can easily store a bigger number in a small space.
  • This data type does not support base conversion functions.
  • Ex:

3.Complex Data type:

  • Complex numbers are specified as <real part>+<imaginary part>j
  • We can use this data type in the mathematical, scientific, and electrical applications.
  • Syntax: a+bj ;  –> a = real part
      –> b = imaginary part
  • Ex: m = 10+20j      –> To get real part –>print(m.real) –>10.0
    • –>To get imaginary part à print(m.imag) –> 20.0
    • Print(type(m))  –> <class ‘complex’>
  • In real part we can use all 4 formats representation .
  • But in the imaginary part should be declared in decimal form only.
  • Ex:

4.bool Data Type:

  • The boolean data type is either True or False. In Python, boolean variables are defined by the True and False keywords.
  • The output <class 'bool'> indicates the variable is a boolean data type.
  • True, internally it stored as 1 or python will be treated True as a 1 internally and False is 0.
  • Ex:

Note: The keywords True and False must have an Upper Case first letter.

4.String(str) Data Type:

  • String, any sequence of character is called string.
  • But in python string means, any sequence of characters should be enclosed with a single quote or double quote.
  • Char data type is not available in python.
  • To represents multi-line string literals then we can use a triple quote.

Note: String literal –> Any sequences of character is called “String literal”

Triple Quote:
  • To represent string with triple quote, then we should use triple single quote or triple double quote.
  • Ex: Triple quote example.
Q2. How to use single and double quotes (‘ ‘,” “) as normal characters in our string?

Print this statement –> The ‘Python’ classes are very useful In “abeyaantrix softlab”