Page 66 - Digicode_AI_class_7
P. 66

In the previous class, you had learned about introduction to coding. In this class, you are going to
            learn more about coding.

            What are Variables?

            Variable is a name given to a location in the memory, to store values or
            data. For example, you must have seen your mother naming boxes in the
            kitchen. That box has a little storage capacity and your mother gave it a       SUGAR        SALT
            name such as, salt, sugar, tea, etc.
            Variables are also similar to a box or a packet. These packets can be
            named, referenced and used to perform various mathematical operations.

            So, a variable has a name (to refer to it), a type (kind of data it store and its size) and a value (data).
            Usually variables are used to hold one or more values, result of calculations, etc.

            Scope of a Variable
            While creating a variable, you should also remember the limits of its usage. For example, the boxes
            that your mother named, can be used in the kitchen and rarely outside of the kitchen. Similarly, a
            variable can also be used in specific areas of a code, known as scope of a variable.

            The scope or accessibility of the variables defined in a program depends where you have declared it
            in each program. Variable defined outside the scope cannot be accessed.

            Naming Variables

            Every  variable  in  a  program  is unique  and  you  need  to  allocate
            variable a unique name. You cannot use the same name of a variable
            more than once.
            Variable name acts as an identifier for that variable and suggest the
            information which it contains.





                     In Covid-19 pandemic time, Avi Schiffmann, a teenager, coded one of the most
                     visited website across the globe ‘ ncov2019.live’, to monitor COVID-19.


            Example: If variable  ‘x’  stores  value  3, variable ‘y’  stores  value  3.  When  we  perform  addition
            operation on ‘x’ and ‘y’, we will get the output as ‘6’.

            Note: Variable is created, when you assign a value to it.
            Rules for Naming a Variable In Python:

               Name your variables in such a way that it describes its purpose.

               Variable name must begin with a letter or an underscore and can range from 1 to 255 characters.
               No special character or spaces are allowed.
               Uppercase and lowercase characters are distinct.

               Keywords (reserved words) cannot be used as a variable.

                 64    DigiCode AI-VII
   61   62   63   64   65   66   67   68   69   70   71