美文网首页
In-place value swapping

In-place value swapping

作者: import_hello | 来源:发表于2018-09-30 00:19 被阅读0次
    # Why Python Is Great:
    # In-place value swapping
    
    # Let's say we want to swap
    # the values of a and b...
    a = 23
    b = 42
    
    # The "classic" way to do it
    # with a temporary variable:
    tmp = a
    a = b
    b = tmp
    
    # Python also lets us
    # use this short-hand:
    a, b = b, a
    

    相关文章

      网友评论

          本文标题:In-place value swapping

          本文链接:https://www.haomeiwen.com/subject/jlkboftx.html