相关疑难解决方法(0)

在引号内使用引号

当我想print在Python中执行命令并且我需要使用引号时,我不知道如何在不关闭字符串的情况下执行此操作.

例如:

print " "a word that needs quotation marks" "
Run Code Online (Sandbox Code Playgroud)

但是当我尝试做我上面做的事情时,我最终关闭了字符串,我不能把我需要的字放在引号之间.

我怎样才能做到这一点?

python string

54
推荐指数
4
解决办法
22万
查看次数

大括号里面的f-string公式不起作用

我在使用Python 3.7.

我在第3行的代码工作正常,但是当我将基础公式插入第4行时,我的代码返回错误:

SyntaxError:f-string:mismatched'(','{'或'[' (错误指向第一个'('第4行'.

我的代码是:

cheapest_plan_point = 3122.54
phrase = format(round(cheapest_plan_point), ",")
print(f"1: {phrase}")
print(f"2: {format(round(cheapest_plan_point), ",")}")
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚第4行有什么问题.

python f-string

2
推荐指数
1
解决办法
606
查看次数

F' 字符串字典时语法无效

当我尝试使用 f'string 字典时,它说语法无效。

def up_low(s):
    d={"upper":0,"lower":0}
    for c in s:
        if c.isupper():
            d["upper"]+=1
            print (f"No. of Upper case characters: {d["upper"]}")
        elif c.islower():
            d["lower"]+=1
            print (f"No. of Lower case characters:{d["lower"]}")
        else:
            pass
Run Code Online (Sandbox Code Playgroud)

它说第 6 行和第 9 行语法无效。

python

2
推荐指数
1
解决办法
706
查看次数

标签 统计

python ×3

f-string ×1

string ×1