PYTHON

Basic Data Types and Operations


Variables:

As we studied earlier, Python is a dynamically typed language, which means you don't have to declare the type of a variable when you create it. A variable in Python is a reserved memory location to store values. You create a variable by assigning a value to it using the = operator.

Creating Variables

a = 7           # Integer
b = 3.14        # Float
name = "Virat"  # String
is_student = True  # Boolean

Rules of Variable:

  • It must start with a alphabet or underscore ("_").
  • It can contain letters, digits, and underscores.
  • It's a Case-sensitive (e.g., name and Name are different).
  • Cannot be a reserved keyword (e.g., for, while, if, etc.).

 

Identifiers:

Name given to any programmable entity (python object, variables, functions, classes, decorators, generators).

Rules of Identifiers:

  • It must start with a alphabet or underscore ("_").
  • It can be alphanumeric but first character must be any alphabet or "_" .
  • No special characters allowed.
  • length of identifiers can be anything but as per PEP8((Python Enhancement Proposal) convention it must be 79 characters.

 

Keywords:

keywords are predefined words which have specific meaning and perform specific task.

Rules of keywords:

  • keywords cannot be variable because we cannot assign any values to them.
  • If we try to store any value, interpreter will raise syntax error.
  • There are totally 35 keywords in python.
  • Among them three are special keywords.
  • True, False, None are 3 special keywords which states value and starts with capital letters.
  • To check list of keywords we have two ways:
help("keywords")
import keyword
keyword.kwlist

 


PYTHON