Naming Variables - Programming Basics - KS3 Computer Science Revision - BBC Bitesize
Naming Variables - Programming Basics - KS3 Computer Science Revision - BBC Bitesize
KS3
Programming basics
Naming variables
Programming is writing computer code to create a
program, in order to solve a problem. To program a
computer, you need to know how programs are
constructed.
Save to My Bitesize
Revise Test
Pages
Arithmetic
Variables
Naming variables
Consider these example variable names, all of which could be variable names
to store the length of a side of a square:
side_length Good
sideLength Good
Example
This Python (3.x) program uses two meaningful names when calculating
the perimeter of a square:
>>> side_length = 5
>>> perimeter = side_length * 4
>>> print(perimeter)
20
Because meaningful names have been used in this code, it is easy to know
what each variable is used for.
Data types
Variables come in all shapes and sizes. Some are used to store numbers, some
are used to store text and some are used for much more complicated types of
data .
String (or str or text). Used for a combination of any characters that appear
on a keyboard, such as letters, numbers and symbols.
Character (or char). Used for single letters.
Integer (or int). Used for whole numbers.
Float (or Real). Used for numbers that contain decimal points, or for
fractions.
Boolean (or bool). Used where data is restricted to True/False or yes/no
options.
In some languages, such as Python, you can simply start using the variable
without declaring it.
Previous page Next page
Related links
Jobs that use Computer Science BBC Click BBC Technology news
Language:
Code Club Subscription Educational App Store Subscription
English
Terms of Use About the BBC Privacy Policy Cookies Accessibility Help Parental Guidance
Contact the BBC Get Personalised Newsletters Why you can trust the BBC Advertise with us
© 2024 BBC. The BBC is not responsible for the content of external sites. Read about our approach to external
linking.