Fetch definitions, synonyms, and antonyms of a word using WordNet.
fetch_definition
fetch_definition.fetch_definition( word, pos=None, top_n=1, max_synonyms=10, include_examples=False, return_type='str',)
Fetch definitions, synonyms, and antonyms of a word using WordNet.
Parameters
Name
Type
Description
Default
word
str
The word to look up.
required
pos
(n, v, a, r)
Part of speech filter: noun (n), verb (v), adjective (a), adverb (r). If None, returns results for all parts of speech. Default is None.
"n","v","a","r"
top_n
int
Number of top-ranked senses to include.
1
max_synonyms
int
Max number of synonyms to show (combined across returned senses).
10
include_examples
bool
If True, include example sentences when available.
False
return_type
str
Format for returned results (currently supports “str”).
"str"
Returns
Name
Type
Description
str
Formatted string of word definition, senses, synonyms, and antonyms.
Raises
Name
Type
Description
LookupError
If WordNet resource is not available.
TypeError
If word is not a string.
ValueError
If word is empty or pos is not valid.
Examples
>>> fetch_definition("happy")Word: happySense 1 (a): feeling or showing pleasure or contentmentSynonyms: cheerful, gay, glad, joyful, joyous, lighthearted, pleasedAntonyms: sad, unhappy
>>> fetch_definition("run", pos="v", top_n=2)Word: runSense 1 (v): move fast by using one's legsSense 2 (v): flee; take to one's heels; cut and runSynonyms: bolt, dash, escape, flow, gallop, go, hurry, jog, move, operateAntonyms: None found