# Python Set difference_update()

In this tutorial, you will learn about the Python Set difference_update() method with the help of examples.

The `difference_update()` method computes the difference between two sets (A - B) and updates set A with the resulting set.

### Example

``````# sets of numbers
A = {1, 3, 5, 7, 9}
B = {2, 3, 5, 7, 11}

# computes A - B and updates A with the resulting set
A.difference_update(B)

print('A = ', A)

# Output: A =  {1, 9}``````

## difference_update() Syntax

The syntax of the `difference_update()` method is:

``A.difference_update(B)``

Here, A and B are two sets.

## difference_update() Parameter

The `difference()` method takes a single argument:

• B - a set whose items won't be included in the resulting set

## difference_update() Return Value

The `difference_update()` doesn't return any value.

## Example: Python difference_update()

``````A = {'a', 'c', 'g', 'd'}
B = {'c', 'f', 'g'}

print('A before (A - B) =', A)

A.difference_update(B)

print('A after (A - B) = ', A)``````

Output

```Original Set = {'a', 'g', 'c', 'd'}
A after (A - B) =  {'a', 'd'}```

In the above example, we have used the `difference_update()` method to compute the difference between two sets A and B and update set A with the resulting set.

Here, `A.difference_update(B)` performs `A - B` and updates set A with value `{'a', 'd'}`
{"ft_lang_label":"__label__en","ft_lang_prob":0.62597543,"math_prob":0.8040651,"size":1135,"snap":"2022-40-2023-06","text_gpt3_token_len":336,"char_repetition_ratio":0.22458002,"word_repetition_ratio":0.06153846,"special_character_ratio":0.33039647,"punctuation_ratio":0.16299559,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99239016,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-01-28T20:25:24Z\",\"WARC-Record-ID\":\"<urn:uuid:bb4aabb7-eca9-42ba-b5ef-8435fd93db76>\",\"Content-Length\":\"101237\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5d32bb4b-5707-4aed-88f0-f0fb45f801b9>\",\"WARC-Concurrent-To\":\"<urn:uuid:e8c4c6eb-8056-4a06-9c36-24d0f6c4fb8e>\",\"WARC-IP-Address\":\"174.138.49.232\",\"WARC-Target-URI\":\"https://www.programiz.com/python-programming/methods/set/difference_update\",\"WARC-Payload-Digest\":\"sha1:PZLSFVCLG3ORVGGSANE4AGIJBZE4LVZI\",\"WARC-Block-Digest\":\"sha1:6H2IH3LGTS4GIA2J7DHM2EU5J7QKZ6Z6\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764499654.54_warc_CC-MAIN-20230128184907-20230128214907-00648.warc.gz\"}"}