Variables

Comments in Python

  • Comment types (inline comment and multi-line)

# This is inline comment in python

"""
This is also multiline comment

"""

'''

This is multiline comment
So, all of it within triple quoted part 
will be treated as a commented code

We also use this multi-line comment for variable declaration

'''

Namespaces in Python

A namespace is a collection of currently defined symbolic names along with information about the object that each name references. You can think of a namespace as a dictionary in which the keys are the object names and the values are the objects themselves. Each key-value pair maps a name to its corresponding object.

In a Python program, there are four types of namespaces:

  1. Built-In

  2. Global

  3. Enclosing

  4. Local

These have differing lifetimes. As Python executes a program, it creates namespaces as necessary and deletes them when they’re no longer needed. Typically, many namespaces will exist at any given time.

https://realpython.com/python-namespaces-scope/

Variables

  • Variables can store data of different types, and different types can do different things

  • We have 3 primitive data types:

    • Text (String)

    • Numerical (Integer, Float, Complex Number)

    • Boolean

  • We have 3 secondary data types:

    • Sequence (List, Tuple, Range)

    • Set

    • Mapping (Dictionary)

Declaring a Variable

In the below discussion, if you don't understand the meaning of the type of variable, read this section again after going through Primitive Data Types and Secondary Data Types Section

  • While assigning values to any variable, no need to declare a variable in advance

  • Reassigning a different type to the same variable is possible

Variable Names - How to write cleaner code?

  • It is possible to check the type of any variable

  • The print statement works to print (especially very important in debugging the code)

    *debug = determine the cause of an error

  • Possible to take input from users

  • 5 and '5' are not equal or same, 5 is of integer type and '5' is of string type

  • Variable type casting is possible (changing the variable type from one another)

Reference For Further Reading

w3 Resource

Last updated

Was this helpful?