What does ‘import x as y’ do in Python?
It imports the module “x” and binds it to the local name “y”.
Example: import streamlit as st lets you call st.selectbox() instead of streamlit.selectbox().
What is ‘from __future__ import annotations’ and why use it?
It postpones evaluation of type annotations to runtime (stores them as strings).
This avoids issues with forward references and can speed imports. In Python 3.11, it’s useful for types that refer to names defined later.
How do you handle exceptions with try/except?
Wrap risky code in try and handle failures in except.
Example:
try:
current_user = fetch_user_access_direct()
except Exception as e:
st.error(f"Error: {e}")
st.stop()What does ‘st.stop()’ imply from a Python control-flow perspective?
It’s a Streamlit-specific exception that halts further execution of the script for that run (like an early return/abort).
What are truthy/falsey values and how are they used in validation?
Values like '', None, 0, 0.0, [], {} are falsey.
The code checks if val in (None, "") and special-cases 0.0 for amounts. Know that 0.0 is falsey but may be valid.
What does dict.get(key, default) do?
It returns the value for key if present, else default.
Example: corporate_switch = current_user.get("corprt_sw", "N").
How do you safely access and remove keys from dictionaries?
Use dict.get to read with a default; dict.pop(key, None) to remove if present without raising KeyError;del dict[key] raises if missing.
How do you build strings with f-strings and format specifiers?
Use f"...{expr:format}...".
Example currency: f"${{x:,.2f}}" yields comma separators and 2 decimals.
How do you join a list of strings?
Use ", ".join(items).
Example: ", ".join(missing_labels).
What does ‘startswith’ do for strings?
Returns True if the string starts with a prefix.
Used to branch on outcomes like outcome.startswith("Denied").
How do you insert into a list at a specific (possibly negative) position?
list.insert(index, item). Negative index counts from the end.
Example: cols.insert(-4, "DNL_AMT") inserts 4 from the end.
How do you iterate with a for-loop and ‘continue’?
continue skips to the next iteration.
Example:
for k in base_required:
if k not in st.session_state:
missing.append(k)
continueHow do you convert between types (int/float/str)?
Use int(x), float(x), str(x). Wrap in try/except for user input.
Example: float(st.session_state.denial_amt).
What is the difference between ‘==’ and ‘is’?
== checks value equality; is checks object identity. Use is None to check against None.
The code uses val in (None, "") which compares values, not identity.
How do raw strings help with regular expressions?
Prefix with r'' to avoid Python interpreting backslashes.
Example: re.search(r"ID:(\d+)\)", text).
How do you extract regex groups with ‘re.search’?
Use match = re.search(pattern, s) then match.group(1) for the first capturing group.
Cast to int if needed.
What is a context manager (‘with’ statement) conceptually?
with ensures setup/teardown around a block by calling \_\_enter\_\_/\_\_exit\_\_.
Streamlit uses it to place widgets in column containers.
How do you write a simple helper function inside another function?
Define it with def name(...): ....
Example:
def quote(val):
if val is None:
return "NULL"
return "'" + str(val).replace("'", "''") + "'"How do you perform early returns in functions?
Use return to exit early after validation or guard checks. This keeps code paths clear.
How do you get today’s date with datetime?
Call datetime.date.today() to get today’s date.
Streamlit date_input accepts/returns datetime.date objects.
What is a docstring and where is it used?
A triple-quoted string at the start of a function/module/class documenting purpose and behavior.
Example: def render_edit_billing_page(): """Render the Edit Billing page.""".
What does ‘elif’ provide over nested ‘if’?
It creates mutually exclusive branches improving readability.
Used for outcome-dependent UI sections.
How do you use ‘sorted(iterable)’ with a list?
Returns a new sorted list.
Example: payors_list = sorted(load_meta_vals('PYR')['VAL_NAME'].tolist()).
How to safely build lists with comprehensions?
[expr for x in iterable if cond].
Example: [c for c in bills.columns if c.endswith("_META_VAL_ID")].