Chapter 3: The world of variables and operators Flashcards
What is a variable?
Data that we need to store and manipulate in our programs
Example of a variable
UserAge (variable) = 0 (initial value)
Do you have to give a variable an initial value every time it is created?
YEAH!!
Can you change the value of a variable later in the program?
Yes
Can multiple variables be defined in one go?
Yes
Example of multiple variables
userAge, userName = 33, ‘Amrapali’
What is Table, chair = ‘brown’, ‘black’ is equivalent to?
Table = Brown Table = Black
What can a variable name in Python contain?
A variable name in Python can contain
1) Letter (a-z, A-Z)
2) Numbers
3) Underscores
Can the first character be a number?
No, the first character cannot be a number. variable name as 2username is invalid.
Example of variable names
userAge, user_age, userAge2
What words cannot be named as usernames?
Words which have a preassigned meaning to them cannot be used as variable names like input and print.
Is username same as userName?
No, because the variable names are case-sensitive
What are the two naming conventions for variables?
1) Camel case notation
2) Using underscores
What is camel case notation? Provide examples
Writing compound words with mixed casing. For example thisIsAVariableName
Example of underscore usage in naming a variable
this _is_a_variable_name