M.E.
M.E.

Reputation: 5496

What does + operator do in this line?

I am trying to modify a method in an existing module to adapt functionality. What does + operator do in this line?

for line in payment.move_line_ids + expense_sheet.account_move_id.line_ids:

Upvotes: 3

Views: 104

Answers (2)

Mayur Vora
Mayur Vora

Reputation: 962

Hello M.E.,

Solution

  • operator of use is concatenation/combine of two List/String/Tupple.

Example

  1. Plus(+) Operator use with two List

    a = [1,2,3]
    b = [4,5]
    print a + b
    output = [1,2,3,4,5]

  2. + operator use with two String

    a = "Vora"
    b = " mayur"
    print a + b
    output = "vora mayur"

  3. + operator use with two tupple

    a = (1,2,3)
    b = (4,5)
    print a + b
    output = (1,2,3,4,5)

Upvotes: 6

Naglis Jonaitis
Naglis Jonaitis

Reputation: 2633

It concatenates account.move.line records from payment.move_line_ids and expense_sheet.account_move_id.line_ids into a single recordset, which is then iterated over. Please note that the result of the __add__ (+) operation might contain duplicates if the same account.move.line is present in both operands. If you want to avoid duplicates, use the | (OR) operator.

Upvotes: 5

Related Questions