原标题:基于Python的语料库数据处理(三)
《Python玩转语料库数据》专栏· 第3篇
1393 字 | 5 分钟阅读
一起来学习用Python进行语料库数据处理吧!
一、条件判断
在执行某个语句前,我们可能需要对某个条件进行判断,并根据条件判断的结果来决定是否执行该语句。这时就需要使用条件判断if。
条件判断if的基本句法为:
if:
在用Python进行语料库数据处理时,常用的条件判断操作符有“”、“<=”、“>=”、“==”以及“!=”。
示例:
str1 = 'Life is short, we use Python.'
iflen(str1) > 10:
print( 'The string has more than 10 characters.') # Print the sentence
str2 = 'Python'
ifstr2.startswith( 'p'):
print(str2)
str1 = 'Life is short, we use Python.'
iflen(str1) > 30:
print( 'The string has more than 30 characters.')
else:
print( 'The string has less than 30 characters.') # Print this sentence
str2 = 'Python