The following code:
echo '<ul>';
while ( $query->have_posts() ) {
$query->the_post();
$title = get_the_title();
echo '<li>' . $title . comments_number() . '</li>';
}
echo '</ul>';
moves the comments ABOVE and outside of the <li>
like this:
1 Comment
Hello world!