Page 96 - Computer Genius Class 06
P. 96

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
                  name such as, salt, sugar, tea, etc.
                                                                                                  SUGAR        SALT
                  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
                   aria le can also  e used in specific areas o  a code   no n as scope o  a  aria le.

                  The scope or accessi ility o  the  aria les defined in a program depends  here you ha e declared it
                  in each program.  aria le defined outside the scope cannot  e 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.

                   aria le name acts as an identifier  or that  aria le 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.



                       94    Computer Genius-VI
   91   92   93   94   95   96   97   98   99   100   101