1/13
Flashcards covering Python variable declaration, syntax rules, naming conventions, snake case, and comment usage based on freeCodeCamp's Python Certification curriculum.
Conceptually, how does Python describe a variable?
Variables are described as labeled boxes used for storing and referencing data of different types.
What is the correct syntax for declaring a variable in Python?
Write the variable name on the left, followed by the assignment operator (=), and the value to store on the right (for example: age = 25).
What is a string in Python, and how must it be written?
A string is a series of characters used to represent text, written enclosed in single quotes (e.g., 'Hello') or double quotes (e.g., "Hello").
What characters can a Python variable name start with?
A variable name can only start with a letter or an underscore (_), never with a number.
What characters are allowed to be used anywhere within a Python variable name?
Letters (a-z, A-Z), digits (0-9), and underscores (_).
How does Python handle casing in variable names such as age, Age, and AGE?
Variable names are case-sensitive, meaning age, Age, and AGE are all treated as separate, unique variables.
Can Python reserved keywords (such as if, class, or def) be used as variable names?
No, variable names cannot use Python reserved keywords.
What error will Python raise if a variable name begins with a number (such as 5variable_name = 5)?
Python will raise a SyntaxError: invalid syntax.
What is snake case, and how is it used in Python variable naming?
Snake case is the convention of writing variable names in lowercase with words separated by an underscore (for example, my_variable_name).
Why is user_age preferred over age or an abbreviation like ua?
Descriptive variable names clearly communicate their purpose to other team members and your future self within a large codebase.
Why should single-letter variable names be avoided?
They should be avoided because they communicate no purpose or meaning.
How are single-line comments defined in Python, and how does Python process them?
Comments begin with a pound symbol (#); Python ignores the symbol and all text following it on that line.
How can multi-line comments be created in Python?
By using consecutive single-line comments, each starting with the pound symbol (#).
What should be used instead of comments to clarify what a variable represents?
The variable names themselves should be chosen descriptively to communicate what they are for, rather than relying on comments to explain them.