first = (1,2,3)
second = (
1,
2,
3,
)
third = 1,2,3
fourth = 1,2,3,
print(f"First: {first}\nSecond: {second}\nThird: {third}\nFourth: {fourth}")First: (1, 2, 3)
Second: (1, 2, 3)
Third: (1, 2, 3)
Fourth: (1, 2, 3)
A comma-separated list denoted by parentheses
Comma-separated list without parentheses
First: (1, 2, 3)
Second: (1, 2, 3)
Third: (1, 2, 3)
Fourth: (1, 2, 3)
# placeholder functions
def calculate_refund(value, tax, discount):
return 1
def get_order_value(user, order_id):
pass
def get_tax(address, dest):
pass
def adjust_discount(user):
return 0
from dataclasses import dataclass
@dataclass
class Order:
id: int
dest: str
@dataclass
class User:
name: str
address: str
user = User("Alice", "Bobsville")
order = Order(1, "Bobsville")
to_refund = (
calculate_refund(
get_order_value(user, order.id),
get_tax(user.address, order.dest),
adjust_discount(user) + 0.1,
),
)
print(type(to_refund))<class 'tuple'>
to_refund variable to a tupleA: (1,)
B: [1]
C: [(1,)]
user = "Alice"
def get_coupon_codes(user):
return [["DEAL20"]]
((a1,),) = get_coupon_codes(user)
(a2,) = get_coupon_codes(user)
((a3),) = get_coupon_codes(user)
(a4) = get_coupon_codes(user)
(a5,) = get_coupon_codes(user)
a6 = get_coupon_codes(user)
assert a1 not in (a2, a3, a4, a5, a6)
assert a2 == a3 == a5
assert a4 == a6a1: DEAL20
a2: ['DEAL20']
a3: ['DEAL20']
a4: [['DEAL20']]
a5: ['DEAL20']
a6: [['DEAL20']]