python学习-字符串和数字相加/turple解码

1.字符串和数字相加

In [1]:object1 = "data" + "analysis" + "visualization"
In [2]:object1
Out[2]:'dataanalysisvisualization'

In [3]:object2 = 1 * 3
In [4]:object2
Out[4]:3

In [5]:object3 = "1" * 3
In [6]:object3
Out[6]:'111'
  • 第一个代码是字符串相加,相当于将字符串粘贴在一起;
  • 第二个代码是纯数学运算,计算1*3=3;
  • 第三个代码是将1用引号引起来作为字符串,表示将1显示三次;

2.turple进行解码

# Define shout_all with parameters word1 and word2
def shout_all(word1, word2):
    
    # Concatenate word1 with '!!!': shout1
    shout1=word1+"!!!"
    
    # Concatenate word2 with '!!!': shout2
    shout2=word2+"!!!"
    
    # Construct a tuple with shout1 and shout2: shout_words
    shout_words=(shout1,shout2)

    # Return shout_words
    return shout_words

# Pass 'congratulations' and 'you' to shout_all(): yell1, yell2
yell1,yell2=shout_all("congratulations","you")

# Print yell1 and yell2
print(yell1)
print(yell2)
  • yell1,yell2=shout_all("congratulations","you"),将shout1赋值给yell1,将shout2赋值给yell2,tuple的unpack
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值