Neither of Pennsylvania's U.S. senators was on the gubernatorial primary ballot Tuesday, but both seem likely to be affected politically by the results of the body contested election.

Sens. H. John Heinz III and Richard S. Schweiker, Republicans known to be interested in higher political offices, backed separate candidates for the GOP nomination. Heinz's candidate won; Schweiker's lost badly.

Political observers in both parties said yesterday that the nomination of Republican Richard L. Thornburg of Pittsburgh, if he is victorious in November, greatly enhances Heinz's prestige and position in the national as well as state GOP, and all but assures him control, of the state's delegation to the 1980 GOP presidential convention.

Those same observers said the sound defeat of Republican David W. Marston serves to widen the gap between Schweiker and the state GOP. Marston, who gained nationwide attention four months ago when he was ousted by President Carter as U.S. attorney in Philadelphia, finished fourth in the seven-candidate Republican race.

Asked whether Tuesday's results spelled the end of his political career, Marston said, "It's certainly not a very auspicious beginning."

The Democratic nomination went to former Pittsburgh mayor Peter F. Flaherty, who edged out former state auditor general Robert P. Casey, a three-time gubernatorial loser. Lt. Gov. Ernest P. Kline finished a distant third, apparently unable to separate himself from the corruptimtainted administration of two-term Gov. Milton J. Shapp.

Flaherty, a political maverick, ran with no endorsements, a staff of one and a campaign war chest about half as large as Thornburgh's.

The winning candidates, although both Pittsburgh natives, have greatly different campaign styles.

Flaherty, 53, is a low-key campaigner who stresses fiscal responsibility and reduction of the tax burden. Thornburgh, 46, is known as one who goes for the jugular. He made his name as a tough, uncompromising federal prosecutor and has stressed as his major theme the need to clean up Pennsylvania's government.

The lieutenant gubernatorial nomination in both parties amounted to a political name game. Republicans nominated political novice - William Scranton III, 30-year-old son of former governor and former U.N. ambassador William Scranton.

Democrats nominated Robert P. Casey, an obscure high school biology teacher from Pittsburgh. He is no relation to the unsuccessful gubernatorial candidate, but apparently won on the strength of his name.

Marston's last-minute campaign - he did not enter the race until early March - may have helped Thornburgh win the GOP gubernatorial nomination. The 35-year-old Marston proved to be more of a spoiler than a factor by collecting about 158,000 votes, the approximate margin between Thornburgh and his closest rival, former Philadelphia district attorney Arlen Specter.

Thornburgh, a former U.S. assistant attorney general, trailed Specter most of election night, winning on the strength of a massive plurality in the western part of the state.

Marston, who carried some of the rural, traditionally conservative counties in the south central portion of the state, split the eastern vote with Specter and the third-place finisher, former state House minority leader Robert Butera.

Pennsylvania GOP Chairman Richard R. Filling said national media attention probably helped Marston, but he got in after three other candidates added that "he didn't do well because had been working for a year and because there was a light turnout (about 40 percent) and because he had no organization."