As mentioned, it has no effect in Canada; an MP (or MLA provincially) can and often has been booted or switched parties. Generally, like the US, a riding is tilted to one party or another, so changing parties has a good chance of costing you your seat. However, you’re set until the next election unless expelled by the house - usually for criminal misdeeds.
Plus, the head of the party (Prime Minister or opposition leader or whatever…) has final say over whether you can file papers next election as representing that party. So you can be nominated by say, the Conservative riding association but be rejected by the Conservative headquarters. Of course, a party that fights the will of the local grassroots is probably writing off that riding, but sometimes the views or actions of the candidate have to be rejected - if they make racist statements or buck the party line, for example.
One candidate in the Canadian NDP was booted from the party for expressing opposition to abortion (being Catholic, IIRC). She then ran as an independent, split the vote with the official candidate, and allowed a different party to win. Another was denied a Reform nomination won as an independent, and later offered inducements as he was dying of cancer to join their party for a crucial vote.
Another problem is that the central parties (who wrote the laws) control the purse strings. Donations to political parties are hugely tax-deductible for the first few hundred. However, except during the actual election this money generally only can go to the central party HQ who can dole it out as needed.
Another tactic, famously used by Jean Chretien in 1993, is to bypass the grassroots. The party HQ can “parachute” a candidate into a riding. Chretien also famously used the “3-hour nomination window” where the people who wanted to run has 3 hours from the notification being passed by the tame captive grass-roots association to get their papers in, signed by a few hundred voters. This because Chretien wanted to reward cronies who supported him, even though they were relatively useless MP’s and in the coming election, the Liberals were sure to win so everyone else wanted in on the action.
So, once the party boots you or you leave, it is difficult to get re-elected but not impossible.
The OP may be wondering about places that have proportional representation, as a previous post mentions. In that case, the voters have voted for the “party list” so if you aren’t on the list any more, why should you stay in parliament? Canada does not have any PR, nor Britain, so I guess that does not apply.
The problem with PR is that the modus operandi of the political animal is therefore no longer grass-roots schmoozing, but central party office politicking. The figurehead leader(s) go out and get the vote, and the people that want the cushy MP jobs and salaries just schmooze the party brass to get high enough on the list to get a seat. As a result, you are more likely to have as MP’s those dipwads who used to play politics on the college student council, than the people who get into politics at the grasssroots level to make changes to the world. Grassroots-selected members turn out badly often enough. Imagine leaving the choice in the hands of some party Central Committee.