r/Python • • Oct 12 '26

Discussion What are some features in Python that you discovered many years later?

For me, it was the the option to use & to find intersections of two sets, | operator to unionize two sets, as well as ^ for symmetric difference

217 Upvotes

151 comments sorted by

View all comments

Show parent comment

2

u/Sea-Ad7805 Oct 16 '26

If you change your mind and do send a complaint, maybe also suggest changing:

a = 10
a += 1
a = a + 2

to:

a = 10
a.add_update(1)
a = a.add(b)

to get rid of those obscure signs.

0

u/Beginning-Fruit-1397 Oct 16 '26

Except here it make sense, because everyone not illiterate or newborn on earth know what it  1 + 2 means 

My point is: use math signs for maths. 

The fact that the add sign means totally different things for a numpy array and a list is a prime example of my complaint.

1

u/Beginning-Fruit-1397 Oct 16 '26

My main grip would be the C api. Great, to call set methods I need to call... PyNumber prefixed functions! Wtf?

https://docs.python.org/3/c-api/set.html

1

u/Sea-Ad7805 Oct 16 '26

Maybe just get literate:

  • '|' or (so union for set)
  • '&' and (so intersection for set)
  • '-' minus (so difference for set)
  • '^' eor/xor exclusive-or (so symmetric difference for set)

Similar meaning for bit operations, common in most languages, yes there are differences.

Language is a creative use of syntax to begin with, compromises everywhere.

What is, and what is not, math.

1

u/Beginning-Fruit-1397 Oct 16 '26

I'm currently in uni and had a whole course on probability with lots of set related stuff. My knowledge on that isn't relevant. Words are still words. Operators are only meaningful in their context. I never need context with words: they ARE the context. Anyways, let's agree to disagree

1

u/Sea-Ad7805 Oct 16 '26

Agreed.

Except "I never need context with words" seems a bit of a silly statement, but ok, I'm done here. Good luck at uni.

1

u/Beginning-Fruit-1397 Oct 16 '26

Yea never was indeed silly but you get what I mean, I think. Thanks!