Lots of Automattic themes do exactly this for standard tags and categories The Underscores starter theme, too. Straight from its source code up on GitHub:
$categories_list = get_the_category_list( esc_html__( ', ', '_s' ) ); if ( $categories_list ) { /* translators: 1: list of categories. */ printf( '' . esc_html__( 'Posted in %1$s', '_s' ) . '', $categories_list ); // WPCS: XSS OK. }
Adapt as needed for your taxonomy.