<?php
use Drupal\user\Entity\User;
// Updating a user is a three step process:
// 1) load the user object to change
// 2) set property/field to new value
// 3) Save the user object.
// This example updates the user name.
// $uid is the user id of the user user update
$user = \Drupal\user\Entity\User::load($uid);
// Don't forget to save the user, we'll do that at the very end of code.
// Modify username
$username = $user->getUsername($username);
$username .= " Hello";
$user->setUsername($username); // string $username: The new user name.
// The crucial part! Save the $user object, else changes won't persist.
$user->save();
// Congratulations, you have updated a user!
I based this on the examples in this Github gist:
https://gist.github.com/dreambubbler/671afd7f962ae46687e41340b396d266