我是 Python 新手,正在尝试从 Perl 学习 Python。在 Perl 中,如果我想将一个字符串与多个子字符串进行比较,我会使用以下内容:
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中做到这一点?