0% found this document useful (0 votes)
7 views

Gr 6.3 - Variables_Constant 5

Uploaded by

naturebuddy2022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Gr 6.3 - Variables_Constant 5

Uploaded by

naturebuddy2022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Variables

Variables – are named memory location.


The value varies during the execution of
the program. Example: - quiz1/quiz2/quiz3
Variable naming conventions.
➢ Always give meaningful variable name.
➢ never start with a number or symbol.
➢ only symbol used is underscore.
➢ keywords cannot be used as variable
names.
➢ Use descriptive names that are not too
short or too long.
➢ Use lowercase for most variable names.
 For variables names with more than one
word use lowercase_with_underscores. ●
 For constants (stored values that don't
change) use UPPERCASE or
UPPERCASE_WITH_UNDERSCORES.
Reserved words
Some words are reserved as
keywords and cannot be used
for variable names.
Here are some examples of reserved
words:​
Activity: Variables and
Constants
In general, variable means not consistent while constants
mean remaining the same for a period of time.
 Every year we celebrate our birthdays.
 What changes on your birthdays?
 The answer is your age.
 What does not changes on your birthday?
 The answer is your name.
So, from here we understand that our age is
variable, while our name is constant. Similarly, in
programming, there are variables and constants.
Variables have a variable name and contain
a value. Age as a variable has a

 Variable name: Age


 Value: Your age in years

Similarly, Constants have a constant name and


a value.
 Constant name: Name
 Value: Your name
Variable value changes but the
constant value does not change
over a period of time.
 Example1: Take a box and place a toy in
the box. so the box is the variable name
and the toy in the box is the variable value.
Now change the toy. What changes now?
What changes the variable name or the
variable value?

 Repeat this with 5 different toys and check


what changes every time.
 Example 2: Again take a box and place a toy in the box. Now
seal the box with the help of a tape.
 Can you change the toy in the box?
 The answer is no. So now the box becomes a constant with a
fixed toy inside it. This means its value cannot be changed.
 The box on the left has a spiderman toy in it. It is
sealed and we cannot change the toy in it. Thus,
the box is constant with a fixed value.
 The box on the right has a spiderman toy in it. It is
open and we can change the toy in it. Thus, the
box is a variable, and its value can be changed.
 Through this activity, we learn about variables and
constants. In detail, there are different types of
variables.
 Variable that can store an integer, a string, or a
boolean value.
First_Name= “Fred S”
name = “Smith”
Age = 15
Year = 10
Tutor_Group = “10WA”
Constant:

 The values will not change during


the execution of the program.
example: - PI(3.14).
Basics of Programming Worksheet 2-
Q1-1,2,3,4,5 in the class

HW
Complete the notes

Basics of Programming
Worksheet 2

You might also like