
Answer-first summary for fast verification
Answer: `f"{region}{store}_sales_{year}"`
## Explanation The correct answer is **D** because: 1. **f-string syntax**: The `f""` prefix creates an f-string (formatted string literal) in Python, which allows embedding expressions inside string literals using curly braces `{}`. 2. **Proper concatenation**: The desired table name format is `nyc100_sales_2021`, which means: - `region` and `store` should be concatenated directly without any separator: `nyc100` - Followed by `_sales_` - Followed by `year` 3. **Why other options are incorrect**: - **A**: Uses regular string without f-string prefix, so variables won't be evaluated - **B**: Uses f-string but includes `+` signs which would create `nyc+100+_sales_2021` instead of `nyc100_sales_2021` - **C**: Regular string without f-string prefix, variables won't be evaluated - **E**: Incorrect syntax mixing string concatenation and variable references 4. **Testing with example values**: ```python region = "nyc" store = "100" year = "2021" table_name = f"{region}{store}_sales_{year}" print(table_name) # Output: nyc100_sales_2021 ``` This approach correctly uses Python's f-string formatting to dynamically create the table name string with the desired format.
Author: Keng Suppaseth
Ultimate access to all questions.
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}
No comments yet.