Python

Esempi di codice

15
0

set python

>>> A = {0, 2, 4, 6, 8};
>>> B = {1, 2, 3, 4, 5};

>>> print("Union :", A | B)  
Union : {0, 1, 2, 3, 4, 5, 6, 8}

>>> print("Intersection :", A & B)
Intersection : {2, 4}

>>> print("Difference :", A - B)
Difference : {0, 8, 6}

# elements not present both sets
>>> print("Symmetric difference :", A ^ B)   
Symmetric difference : {0, 1, 3, 5, 6, 8}
15
0

operatori bit a bit python

x << y
Returns x with the bits shifted to the left by y places (and new bits on the right-hand-side are zeros). This is the same as multiplying x by 2**y.
x >> y
Returns x with the bits shifted to the right by y places. This is the same as //'ing x by 2**y.
x & y
Does a "bitwise and". Each bit of the output is 1 if the corresponding bit of x AND of y is 1, otherwise it's 0.
x | y
Does a "bitwise or". Each bit of the output is 0 if the corresponding bit of x AND of y is 0, otherwise it's 1.
~ x
Returns the complement of x - the number you get by switching each 1 for a 0 and each 0 for a 1. This is the same as -x - 1.
x ^ y
Does a "bitwise exclusive or". Each bit of the output is the same as the corresponding bit in x if that bit in y is 0, and it's the complement of the bit in x if that bit in y is 1.
5
0

** in python

#** is the exponent symbol in Python, so:
print(2 ** 3)
#output: 8
4
0

operatori logici python

not 
and 
or
2
0

python >>

# >> and << are bitwise operators. They shift the bits of an integer right and left
# 7 = 0111
print(7 >> 1)
# 3  (0011)

print(7 << 1)
# 14 (1110)
1
0

e in python

#And opreator in python

a = 12
b = 56

print(a and b * 12)

Pagine correlate

Pagine di esempio simili

In altre lingue

Questa pagina è in altre lingue

Русский
..................................................................................................................
English
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................