0

What is the purpose of this line?

id, now = id+1, time.ctime()

I've never seen this usage of commas in Python before and I'm not sure how to Google this.

import zmq
import time

# ZeroMQ Context
context = zmq.Context()

# Define the socket using the "Context"
sock = context.socket(zmq.PUSH)
sock.bind("tcp://127.0.0.1:5690")

id = 0

while True:
    time.sleep(1)
id, now = id+1, time.ctime()

# Message [id] - [message]
message = "{id} - {time}".format(id=id, time=now)

sock.send(message)

print "Sent: {msg}".format(msg=message)
Quake
  • 105
  • 1
  • 10

2 Answers2

1

This is a single command to assign values to two variables. It will be same as

id = id+1
now = time.ctime()
theBrainyGeek
  • 584
  • 1
  • 6
  • 17
0

keyword to google is 'tuple' . Its a immutable comma seperated list of values

kar
  • 198
  • 1
  • 8
  • `('some', 'values')` is also a tuple, an immutable comma-separated list of values – Adam Smith Nov 01 '17 at 20:17
  • ok I helped him with the key word to google : "I've never seen this usage of commas in Python before and I'm not sure how to Google this" . I only answered part of his answer. I have edited my answer – kar Nov 01 '17 at 20:20