我是Python的新手,並試圖從Perl學習python。在Perl中,如果我想比較對多個子串一串,我會用以下內容:Python:比較字符串變量和多個子字符串
sub matchCity {
my $cityName = shift;
print "$cityName is a valid city name\n" if ($cityName =~ /kyo|par|omba/);
}
matchCity('tokyo'); # tokyo is a valid city name
matchCity('paris'); # paris is a valid city name
matchCity('bombay'); # bombay is a valid city name
matchCity('chicago'); # Doesn't print anything
我怎樣才能在Python這樣做呢?
什麼是錯誤的與芝加哥!?! –