Section 2.5 Variables
|Learning Objective: |
You might notice that every time we display the prompt we take the user’s input and store into the class# variable. What we are doing here is called an assignment. We are setting the value of the Variable to be something so that later on we can perform calculations with it later.
You are allowed to name your variables whatever you wish however, there are some restrictions depending on the programming language you are using and also some conventions that are widely adopted among programmers. The general restrictions are:
variables can not contain spaces
They typically do not start with numbers
They typically can not be characters that are not numeric, alphabetical, or under_scores.
Yes, num is correct.
Yes, class4 is correct.
Remember that variables cannot start with numbers
Remember that variables cannot have spaces between them
Which of these are valid variable names?
Variables cannot start with numbers and cannot have spaces between them.
Often programmers use camelCase. camelCase is the practice of writing phrases without spaces or punctuation, indicating the separation of words with a single capitalized letter, and the first word starting with either case. Another style is snake_case, which uses under_scores to represent spaces