Exclude a post using a dynamic id

This is useful for instance in a portfolio where you would like to show the items on the single pages but do not wish for the current post to show up in the loop. In my occurrence I needed this to function outside of the loop for the dynamic work section that displays on the home page.

Code Markup
// Works inside and outside of the Loop, returns the ID.
function getpostid() {
global $post;
$thepostid = $post->ID;
return $thepostid;
}

// Check if page is a single item, if so it returns the ID for the function.
if ('is_singular') {
  $postid = getpostid();
}

// Use this in the WP_Query to exclude the returned ID from the loop.
$args = array (
  'post__not_in' => array( $postid )
);