zoukankan      html  css  js  c++  java
  • python中字符串的合并(f字符串,在变量中使用字符串)

    >>> a = "string1"
    >>> b = "string2"
    >>> print(ab)  ## 直接输出报错
    Traceback (most recent call last):
      File "<pyshell#33>", line 1, in <module>
        print(ab)
    NameError: name 'ab' is not defined
    >>> ab = f"{a} {b}"   ## 使用f合并字符串
    >>> print(ab)
    string1 string2
    >>> print(ab,"strints")
    string1 string2 strints
    >>> print(f"{ab} strints")
    string1 string2 strints
    >>> print("xxxx")
    xxxx
    >>> print("yyyy")
    yyyy
    >>> print("xxxx""yyyy")
    xxxxyyyy
    >>> print("xxxx","yyyy")
    xxxx yyyy
    >>> a = "mmmm"
    >>> b = "nnnn"
    >>> c = "oooo"
    >>> print(bc)
    Traceback (most recent call last):
      File "<pyshell#111>", line 1, in <module>
        print(bc)
    NameError: name 'bc' is not defined
    >>> print(b,c)
    nnnn oooo
    >>> print(a,b,c)
    mmmm nnnn oooo
  • 相关阅读:
    组合数取模的题……
    对组合数取模
    n!(n的阶乘)
    八、元素绑定
    七、Application类
    RC振荡电路
    运算放大器工作原理
    No
    合并查询结果
    连接查询
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14140202.html
Copyright © 2011-2022 走看看