line, = plot(x,sin(x)) what does comma stand for?

前端 未结 2 756
陌清茗
陌清茗 2020-12-06 02:02

I\'m trying to make an animated plot. Here is an example code:

from pylab import *
import time

ion()

tstart = time.time()               # for profiling
x =         


        
相关标签:
2条回答
  • 2020-12-06 02:36

    The comma is Python syntax that denotes either a single-element tuple. E.g.,

    >>> tuple([1])
    (1,)
    

    In this case, it is used for argument unpacking: plot returns a single-element list, which is unpacked into line:

    >>> x, y = [1, 2]
    >>> x
    1
    >>> y
    2
    >>> z, = [3]
    >>> z
    3
    

    An alternative, perhaps more readable way of doing this is to use list-like syntax:

    >>> [z] = [4]
    >>> z
    4
    

    though the z, = is more common in Python code.

    0 讨论(0)
  • 2020-12-06 02:38

    case1:

    a=1,
    type(a)
    tuple
    

    case2:

    a=1
    type(a)
    int
    
    0 讨论(0)
提交回复
热议问题