
Answer-first summary for fast verification
Answer: `f"{region}{store}_sales_{year}"`
## Explanation To construct the table name `nyc100_sales_2021` using Python variables `region`, `store`, and `year`, we need to use Python's f-string formatting correctly. Let's analyze each option: - **Option A**: `" {region}+{store}+_sales_{year}"` - This is a regular string, not an f-string, so the variables won't be interpolated. It would literally output `" {region}+{store}+_sales_{year}"`. - **Option B**: `f"{region}+{store}+_sales_{year}"` - This uses f-string formatting but includes `+` characters between variables, which would result in `nyc+100+_sales_2021` instead of the desired `nyc100_sales_2021`. - **Option C**: `" {region}{store}_sales_{year}"` - This is a regular string without f-string prefix, so variables won't be interpolated. - **Option D**: `f"{region}{store}_sales_{year}"` - **CORRECT**: This uses f-string formatting correctly without any extra characters between variables. When `region = "nyc"`, `store = "100"`, and `year = "2021"`, it will produce exactly `nyc100_sales_2021`. - **Option E**: `{region}+{store}+_sales_"+{year}` - This is invalid Python syntax that would cause a syntax error. **Key points**: - F-strings (formatted string literals) are prefixed with `f` or `F` - Variables are placed directly inside curly braces `{}` - No concatenation operators like `+` are needed between variables in f-strings - The desired output format is `{region}{store}_sales_{year}` without any separators between region and store Therefore, option D is the correct choice for dynamically creating the table name string in Python.
Author: LeetQuiz .
Ultimate access to all questions.
No comments yet.
Question 24
A data engineer needs to dynamically create a table name string using three Python variables: region, store, and year. An example of a table name is below when region = "nyc", store = "100", and year = "2021":
nyc100_sales_2021
Which of the following commands should the data engineer use to construct the table name in Python?
A
" {region}+{store}+_sales_{year}"
B
f"{region}+{store}+_sales_{year}"
C
" {region}{store}_sales_{year}"
D
f"{region}{store}_sales_{year}"
E
{region}+{store}+_sales_"+{year}