Python nastavi presek_update ()

The intersection_update () posodobi metodo, ki kliče intersection_update (), s presečiščem množic.

Presečišče dveh ali več nizov je nabor elementov, ki so skupni vsem nizom.

Če želite izvedeti več, obiščite Python set Intersection.

Sintaksa intersection_update()je:

 A.intersection_update (* other_sets)

intersection_update () Parametri

intersection_update()Metoda omogoča poljubno število argumentov (kompleti).

Opomba: * ni del sintakse. Uporablja se za označevanje, da metoda omogoča poljubno število argumentov.

Vrnjena vrednost iz Intersection_update ()

Ta metoda vrne None(kar pomeni, da nima vrnjene vrednosti). Posodobi samo nabor, ki kliče intersection_update()metodo.

Na primer:

 result = A.intersection_update(B, C)

Ko zaženete kodo,

  • rezultat bo None
  • A bo enako presečišču A, B in C
  • B ostaja nespremenjen
  • C ostaja nespremenjen

Primer 1: Kako deluje intersection_update ()?

 A = (1, 2, 3, 4) B = (2, 3, 4, 5) result = A.intersection_update(B) print('result =', result) print('A =', A) print('B =', B)

Izhod

 rezultat = Brez A = (2, 3, 4) B = (2, 3, 4, 5)

Primer 2: intersection_update () z dvema parametroma

 A = (1, 2, 3, 4) B = (2, 3, 4, 5, 6) C = (4, 5, 6, 9, 10) result = C.intersection_update(B, A) print('result =', result) print('C =', C) print('B =', B) print('A =', A)

Izhod

 rezultat = Brez C = (4) B = (2, 3, 4, 5, 6) A = (1, 2, 3, 4)

Zanimive Članki...