三重引号中的字符串不会附加到变量
String in triple quotation won't attach to variable
我一直收到这个错误
”文件 "ex24.py",第 4 行
诗=“”“
^
语法错误:语法无效“
在此代码中:
print ("Let's practice everthing.")
print ('You\'d need to know \'bout escapes with \ that do \n newlines and \t tabs.'
poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none.
"""
print ("--------------")
print (poem)
print ("--------------")
five = 10 - 2 + 3 - 6
print ("This should be five: %s" % (five))
def secret_formula(started):
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars / 100
return jelly_bean, jars, crates
start_point = 10000
beans, jars, crates = secret_formula (start_point)
print ("With a starting point of: %d" % (start_point))
print ("We'd have %d beans, %d jars, and %d crates." % (beans, jars, crates))
start_point = start_point / 10
print ("We can also do that this way:")
print ("We'd have %d beans, %d jars and %d crates." % (secret_formula(start_point))
我不明白我在 poem 变量中犯了哪个错误,因为我可以
当我让变量在一个文件中为自己工作时,代码能正常工作吗?
您在第二行末尾缺少括号。参见 here。
print ("Let's practice everthing.")
print ('You\'d need to know \'bout escapes with \ that do \n newlines and \t tabs.')
poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none.
"""
我一直收到这个错误
”文件 "ex24.py",第 4 行 诗=“”“ ^ 语法错误:语法无效“
在此代码中:
print ("Let's practice everthing.")
print ('You\'d need to know \'bout escapes with \ that do \n newlines and \t tabs.'
poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none.
"""
print ("--------------")
print (poem)
print ("--------------")
five = 10 - 2 + 3 - 6
print ("This should be five: %s" % (five))
def secret_formula(started):
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars / 100
return jelly_bean, jars, crates
start_point = 10000
beans, jars, crates = secret_formula (start_point)
print ("With a starting point of: %d" % (start_point))
print ("We'd have %d beans, %d jars, and %d crates." % (beans, jars, crates))
start_point = start_point / 10
print ("We can also do that this way:")
print ("We'd have %d beans, %d jars and %d crates." % (secret_formula(start_point))
我不明白我在 poem 变量中犯了哪个错误,因为我可以 当我让变量在一个文件中为自己工作时,代码能正常工作吗?
您在第二行末尾缺少括号。参见 here。
print ("Let's practice everthing.")
print ('You\'d need to know \'bout escapes with \ that do \n newlines and \t tabs.')
poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none.
"""