2

VARIABLES AND DATATYPES

by

The Education Machine

[support@theeducationmachine.com]

Below are the topics covered in this tutorial:

  1. Datatypes in Python
  2. What are Variables
  3. Naming Convention for variables
  4. What are reserved keywords
  5. How to view reserved keywords

Datatypes in Python


There are 6 standard datatypes in Python:

  1. Integer
  2. String
  3. Tuple
  4. List
  5. Set
  6. Dictionary

All above datatypes will be discussed 1-by-1 in detail in the coming sessions

** Once we are well-versed python, we will start working on Libraries such as Numpy, Pandas where we will learn some additional datatypes such as Arrays and Dataframes


Mutable and Immutable


*This is an important concept to understand theoretically. In following sessions, we will see the difference:
Immutable: For immutable datatypes, once value is defined for a variable, it cannot be changed or altered. It can only be overwritten.
1.Numbers, we already saw an example :)
2.Strings
3.Tuples
Mutable: For mutable datatypes, once value is defined for a variable, it can be changed, altered or overwritten.
1.List
2.Set
3.Dictionary


Variables in Python


Variables are the containers which store some values in it.

Each variable consume some memory and have specific memory locations. In other words, When a user creates a variable, it reserves some space in memory.

Unlike other languages, in python we do not explicitly specify the datatype to be used for a variable. Rather interpreter reads the line and decides the datatype of the variable as per the value given to the variable and reserves memory accordingly.

Equal sign(=) is used to assign a value to a variable. Assigning a value to a variable is knows as variable declaration.

On the left hand of (=) is the variable name and on the right side of (=) is the variable's value.


List of Rules or Naming Convention for Variables:


  1. Variable Name can only be started with an alphabet or an "_"
  2. Cannot be started with a number however inbetween variable name, a number can occur
  3. Special characters are not allowed
  4. There is no length defined in python for variable name, can be any length
  5. Reserved keywords of python cannot be used as Variable name, some keywords can work but is not recommended
  6. Variable names are case sensitive

What are reserved Keywords?


Reserved Keywords are bag of words which are preserved by python to accomplish specific tasks. Such keywords should not be used as variable names to avoid any errors and to make python's interpreter task easy.

How to view reserved Keywords of Python?


We will use help( ) function to find out all reserved keywords.

help( ) function is used to pull out documentation of any keyword in python


To find out all reserved keywords:

help('keywords')

reserved_keywords

To fetch documentation for specific keyword:

help('for')

reserved_keywords

**for keyword is reserved to process loops in python