Python: Declaring Variables and Naming Conventions

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/13

flashcard set

Earn XP

Description and Tags

Flashcards covering Python variable declaration, syntax rules, naming conventions, snake case, and comment usage based on freeCodeCamp's Python Certification curriculum.

14 Terms

1
New cards

Conceptually, how does Python describe a variable?

Variables are described as labeled boxes used for storing and referencing data of different types.

2
New cards

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).

3
New cards

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").

4
New cards

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.

5
New cards

What characters are allowed to be used anywhere within a Python variable name?

Letters (a-z\text{a-z}, A-Z\text{A-Z}), digits (0-90\text{-}9), and underscores (_\_).

6
New cards

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.

7
New cards

Can Python reserved keywords (such as if, class, or def) be used as variable names?

No, variable names cannot use Python reserved keywords.

8
New cards

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.

9
New cards

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).

10
New cards

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.

11
New cards

Why should single-letter variable names be avoided?

They should be avoided because they communicate no purpose or meaning.

12
New cards

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.

13
New cards

How can multi-line comments be created in Python?

By using consecutive single-line comments, each starting with the pound symbol (#\#).

14
New cards

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.