Python| TextBlob.sentiment() 方法
借助TextBlob.sentiment()
方法,我们可以通过TextBlob.sentiment()
方法获取句子的情感。
Syntax : TextBlob.sentiment()
Return : Return the tuple of sentiments.
示例 #1:
在这个例子中,我们可以说通过使用TextBlob.sentiment()
方法,我们能够得到一个句子的情绪。
# import TextBlob
from textblob import TextBlob
gfg = TextBlob("GFG is a good company and always value their employees.")
# using TextBlob.sentiment method
gfg = gfg.sentiment
print(gfg)
输出 :
Sentiment(polarity=0.7, subjectivity=0.6000000000000001)
示例 #2:
# import TextBlob
from textblob import TextBlob
gfg = TextBlob("Sandeep Jain An IIT Roorkee alumnus and founder of GeeksforGeeks. He loves to solve programming problems in most efficient ways.")
# using TextBlob.sentiment method
gfg = gfg.sentiment
print(gfg)
输出 :
Sentiment(polarity=0.5, subjectivity=0.5)