• Tuple assignment


    It is often useful to swap the values of two variables. With conventional assignments, you have to use a temporary variable. This solution is cumbersome; tuple assignment is more elegant:

                           

    The left side is a tuple of variables; the right side is a tuple of expressions. Each value is assigned to its respective variable. All the expressions on the right side are evaluated before any of the assignments. The number of variables on the left and the number of values on the right have to be the same:

     

    More generally, the right side can be any kind of sequence (string, list or tuple). For example, to split an email address into a user name and a domain, you could write:

     

     

    from Thinking in Python

  • 相关阅读:
    课后作业5
    类与对象动手动脑
    动手动脑
    找“水王”
    NABCD
    第七周学习进度
    web网页四则运算
    二维数组最大联通子数组求和
    第六周学习进度
    环状数组最大子数组求和
  • 原文地址:https://www.cnblogs.com/ryansunyu/p/3854983.html
Copyright © 2020-2023  润新知