0

Please look at the below code.

signal = {
    "id": "p752",
}

class Trigger:
    def __init__(self, signal):
        self.id = signal['id'],
        
        print(type(signal['id']))
        print(type(self.id))
    
    def get_trigger(self):
        print(self.id)


t1 = Trigger(signal)
t1.get_trigger()

The output I get is

<class 'str'>
<class 'tuple'>
('p752',)

I honestly don't know what is happening here. When I assign signal['id'] to 'id' inside the constructor why is changing to a tuple?

codeyashu
  • 55
  • 2
  • 7

1 Answers1

0
self.id = signal['id']

Trailing comma is to be removed so it is treated as a tuple

hedy
  • 1,160
  • 5
  • 23