OR ( | ) ์—ฐ์‚ฐ์ž

2020. 6. 22. 19:48ใ†Backend/๐Ÿ Python

๋ณดํ†ต or ( '|' ) ์—ฐ์‚ฐ์ž๋ฅผ ๋– ์˜ฌ๋ฆฌ๋ฉด ๋น„ํŠธ์—ฐ์‚ฐ์ž๋กœ์„œ ์•„๋ž˜์™€ ๊ฐ™์€ ํ˜•ํƒœ๋ฅผ ๋– ์˜ฌ๋ฆฐ๋‹ค.

1 or 1 = 1
1 or 0 = 1
0 or 1 = 1
0 or 0 = 0

1 | 1 = 1
1 | 0 = 1
0 | 1 = 1
0 | 0 = 0

ํ•˜์ง€๋งŒ, ํŒŒ์ด์ฌ์—์„œ '|' ์—ฐ์‚ฐ์ž๋Š” ์ •์ˆ˜ํ˜•๋ผ๋ฆฌ ์‚ฌ์šฉํ•  ๋•Œ์™€, set type๋ผ๋ฆฌ ์‚ฌ์šฉํ•  ๋•Œ ๊ฒฐ๊ณผ๊ฐ€ ๋‹ค๋ฅด๊ฒŒ ๋‚˜์˜จ๋‹ค.

  • ์•„๋ž˜๋Š” set type๋ผ๋ฆฌ ์‚ฌ์šฉํ•œ ๊ฒฐ๊ณผ์ด๋‹ค.
a = set([1,2,3])
b = set([2,3,4])
c = a|b

print(c)
>>> {1, 2, 3, 4}

์ฆ‰ ์„œ๋กœ ๋‹ค๋ฅธ set type์—์„œ '|' ์—ฐ์‚ฐ์ž์˜ ์‚ฌ์šฉ์€,

๋‘ set์„ ํ•˜๋‚˜๋กœ ํ•ฉ์น˜๋ฉด์„œ uniqueํ•œ ๊ฐ’๋งŒ ์ทจํ•˜๋Š” ์ง‘ํ•ฉ์ด ๋œ๋‹ค.