TextBlob.sentiment() method

Last Updated : 23 May, 2026

Sentiment analysis is used to identify the emotional tone of text as positive, negative or neutral. The TextBlob.sentiment() method provides two important measures for analyzing text sentiment.

  • Polarity: Indicates whether the text is positive, negative, or neutral
  • Subjectivity: Measures whether the text is opinion-based or factual

Example

Python
from textblob import TextBlob

text = "GFG is a good company and always value their employees."
blob = TextBlob(text)
sentiment = blob.sentiment
print(sentiment)

Output:

Sentiment(polarity=0.7, subjectivity=0.6000000000000001)

  • Polarity: 0.7 means positive sentiment.
  • Subjectivity: 0.6 means it’s more opinion-based.

Syntax:

TextBlob.sentiment

Return:

  • Polarity: A score between -1 (negative) and 1 (positive) showing how positive or negative the text is.
  • Subjectivity: A score between 0 (factual) and 1 (opinion-based) showing how subjective or objective the text is.

Lets see some more examples:

Example 1: Negative Sentiment

Here, we analyze a sentence that expresses a strong negative sentiment. The polarity score reflects the negative tone while the subjectivity shows opinion-based statement.

Python
text = "I hate bugs in my code."
blob = TextBlob(text)
sentiment = blob.sentiment
print(sentiment)

Output:

Sentiment(polarity=-0.8, subjectivity=0.9)

  • Polarity: -0.8 shows a negative sentiment.
  • Subjectivity: 0.9 shows the text is highly opinion-based.

Example 2: Neutral Sentiment

In this example, we’ll analyze a neutral sentence that conveys factual information without expressing any strong opinion or emotion. It will show how TextBlob classifies a sentence with no sentiment bias.

Python
text = "The sun rises in the east."
blob = TextBlob(text)
sentiment = blob.sentiment
print(sentiment)

Output:

Sentiment(polarity=0.0, subjectivity=0.0)

  • Polarity: 0.0 means neutral.
  • Subjectivity: 0.0 shows it's factual.

Example 3: Mixed Sentiment

Here the sentence presents a neutral sentiment but is more opinion-based than factual. The polarity score remains neutral while the subjectivity score reflects an opinion or preference.

Python
text = "I enjoy coding, but debugging can be frustrating."
blob = TextBlob(text)
sentiment = blob.sentiment
print(sentiment)

Output:

Sentiment(polarity=0.0, subjectivity=0.7)

  • Polarity = 0.0: This shows a neutral sentiment.
  • Subjectivity = 0.7: The text is more opinion-based than factual as it's expressing a preference.

Download code from here

Applications

  • Used in social media monitoring to analyze public opinion and trends
  • Helps businesses evaluate customer feedback and satisfaction levels
  • Supports content moderation by detecting negative or inappropriate comments
  • Assists in understanding user emotions and reactions in real time

Limitations

  • Struggles to understand sarcasm and irony accurately
  • Uses a basic lexicon, limiting understanding of complex text
  • May misinterpret sentences containing mixed sentiments
  • Less effective for nuanced or context-dependent language
Comment