WASHINGTON — When Donald J. Trump set his sights on the presidency in the 2000 election, he pursued the nomination of the Reform Party, a home for disenchanted independents. “The Republican Party has just moved too far to the extreme right,” he explained. “The Democrats are too far to the left.”

In the end, he dropped the campaign and the Reform Party, the leftover construct from Ross Perot’s two independent presidential candidacies during the 1990s. It was one of at least five times that Mr. Trump would switch party affiliations over the years. “I’m the Lone Ranger,” he once said in another context.

Now in the White House, President Trump demonstrated this past week that he still imagines himself a solitary cowboy as he abandoned Republican congressional leaders to forge a short-term fiscal deal with Democrats. Although elected as a Republican last year, Mr. Trump has shown in the nearly eight months in office that he is, in many ways, the first independent to hold the presidency since the advent of the current two-party system around the time of the Civil War.

In recent weeks, he has quarreled more with fellow Republicans than with the opposition, blasting congressional leaders on Twitter, ousting former party officials in his White House, embracing primary challenges to incumbent lawmakers who defied him and blaming Republican figures for not advancing his policy agenda. On Friday, he addressed discontent about his approach with a Twitter post that started, “Republicans, sorry,” as if he were not one of them, and said party leaders had a “death wish.”