How to get and set config in Drupal 8

Drupal 8 provides configuration manager module which helps in managing configuration across the various environment of the same website, the configuration can be fetched and altered in a custom module in following way. 

//Fetching Site Name using configuration.
$site_name = \Drupal::config('system.site')->get('name');
//To edit configuration as well use getEditable method.
$config = \Drupal::service('config.factory')->getEditable('system.site');
// Setting DrupalABC as Sitename.
$config->set('name', 'DrupalABC')->save();