New Zealand Prime Minister David Lange said today that he will introduce legislation by early December to formally ban U.S. warships carrying nuclear weapons from visiting his country.

U.S. officials have asserted that such a step will sharpen the challenge that they believe New Zealand's policy of excluding nuclear weapons from its territory poses for the Reagan administration in managing alliances around the world. Enshrining that policy in law would trigger a further reassessment of military relations between the two nations, these officials say.

Lange laid repeated and heavy emphasis during an interview on his desire to continue strong defense ties to the United States.

"Our antinuclear policy is not an anti-American policy," he said. "It is impossible to be anti-American in New Zealand and be a political survivor." But he insisted that public sentiment in New Zealand dictates that these ties have to be on a nonnuclear basis.

Questioned about a second major international dispute in recent months that has thrust New Zealand onto the front pages -- the confrontation with France over the sinking of the environmental ship Rainbow Warrior by French secret agents -- Lange lamented that the episode seems to have hardened France's insistence on continued nuclear testing in the Pacific.

The prime minister, who is here to address the U.N. General Assembly Thursday, noted that he had held the legislation affecting U.S. warships back for nearly a year in hopes of reaching a compromise with the United States, but efforts to do so had failed.

Stressing that New Zealand "is not nonaligned" and wants to continue to play a role with conventional forces in western defense of the Pacific, Lange praised the Reagan administration for its "honorable and disciplined" attitude in ruling out economic sanctions against his island nation.

He acknowledged, however, that decisions by the United States to curtail cooperation on intelligence matters and to halt joint military exercises had forced New Zealand to build up stockpiles of ammunition and take other steps that will add 120 million New Zealand dollars, or about $68 million, to defense spending this year.

Lange, a Methodist minister who led his Labor Party to victory in elections in July 1984, appeared buoyed by new public opinion polls that give his government unusually high approval ratings and strongly supporting its rejection of an American nuclear shield. But those polls also show strong public support for the defense ties to the United States embodied in the ANZUS defense treaty, which requires Australia, New Zealand and the United States to consult in the event of military attack.

Lange said that the United States and New Zealand had a good working relationship for 150 years "and I don't want to be the prime minister of a government that blows it."

But the concept of the ANZUS treaty and of New Zealand's defense role that he outlined during the interview was one sharply at odds with the views of the Reagan administration, which maintains that an allied nation's willingness to receive American warships is an essential part of a defense relationship.

"ANZUS was not a nuclear alliance," Lange maintained, noting that New Zealand "had no part of a command structure" as NATO countries do and that New Zealand accepted only "a conventional defense" role under ANZUS.

New Zealand, he said, does not perceive itself as facing "an imminent threat . . . . We see defense not necessarily in terms of military might or installations or defense outposts."

The United States has long refused to confirm or deny whether ships making port calls in allied countries carry nuclear weapons. Lange said that the compromise he had proposed involved the United States continuing that policy while New Zealand reserved the right to make its own judgment and decline to receive American ships it believed to be carrying nuclear weapons.

Asked about the bombing of the ship belonging to the Greenpeace antinuclear group in New Zealand by French secret service agents this summer, Lange said negotiations on compensation will be resumed between the two nations in New York later this month.

He deplored the political consequences of the bitter dispute, which he said apparently has "entrenched nuclear testing by the French in the South Pacific" rather than deterring it. The French government, he said, has whipped up "military nationalistic fervor" in the face of New Zealand's criticism of nuclear testing in general.