zoukankan      html  css  js  c++  java
  • python-字符串中含有变量的表示方法

    name='liming'
    age = 20

    #1 字符串拼接,变量age必须是str类型
    print('he is '+str(age)+' years old')
    执行结果
    he is 20 years old

    #2 %s代表变量,
    print('he is %s years old' % age)
    执行结果
    he is 20 years old

    #3 format
    print('{} is {} years old'.format(name,age))
    print('{0} is {1} years old'.format(name,age))
    print('{name_} is {age_} years old'.format(name_=name,age_=age))
    执行结果
    liming is 20 years old
    liming is 20 years old
    liming is 20 years old
  • 相关阅读:
    @bzoj
    @bzoj
    @codeforces
    @codeforces
    @bzoj
    @codeforces
    @codeforces
    @codeforces
    @NOIP2018
    反转字符串--C和Python
  • 原文地址:https://www.cnblogs.com/wsnan/p/11389613.html
Copyright © 2011-2022 走看看