動作確認
CentOS 6.5(32bit)
文字列に\n
が含まれるかのチェック。
参考 http://d.hatena.ne.jp/laco0416/20121022/1350907756
[追記]
関数を使わずにinステートメントでも解決できるようです。
if 'fuga' in 'hogehoge':
151109a.py
def main():
res = ""
str = ""
if (len(str) > 0):
res = res + str
if "\n" in res:
print "found 1"
str = "hello"
if (len(str) > 0):
res = res + str
if "\n" in res:
print "found 2"
str = ".bonjour\n"
if (len(str) > 0):
res = res + str
if "\n" in res:
print "found 3"
if __name__ == "__main__":
exit(main())
結果
found 3