President Carter telephoned the shah of Iran yesterday to express his regret at the recent violence in Iran and to reaffirm his belief in the importance of Iran's continued alliance with the West.

The White House announced that Carter called from Camp David, Md., where he is meeting with Eygptian President Anwar Sadat and Israeli Prime Minister Menachem Begin. The president expressed hope that the movement toward political liberalization in Iran will continue, the White House statement said.

Meanwhile, in Tehran, four deputies of the opposition Pan-Iranist Party walked out of the Iranian parliament to protest the slaying of antigrovernment demonstrators during clashes with troops Friday.

The official death toll in the demonstrations, based on coroner's certificates, rose to 95, but unofficial estimates place the number killed at several hundred.

One persons was reported killed yesterday when troops fired into a crowd of religious Moslems in the holy city of Qom, but otherwise quiet prevailed on the third day of martial law. Troops continued to patrol Tehran, the government imposed censorship on news agency photographs transmitted out of the country, and the military governor of Tehran warned that persons convicted of acts against the government will be executied.