在Python代码中,回车是否重要?

在Python代码中,回车是否重要?,python,indentation,carriage-return,Python,Indentation,Carriage Return,我有以下代码: def find_clickable(driver, locator): element = None try: if locator.startswith('//'): element = driver.find_element_by_xpath(locator) else: element = driver.find_element_by_link_text(locator) except: raise Except

我有以下代码:

def find_clickable(driver, locator):
  element = None
  try:
    if locator.startswith('//'):
      element = driver.find_element_by_xpath(locator)
    else:
      element = driver.find_element_by_link_text(locator)
  except:
    raise Exception('Could not find element to click "%s"' % locator)
  if not element.is_displayed():
    raise Exception('Element to click "%s" is present but is not displayed')
  if not element.is_enabled():
    raise Exception('Element to click "%s" is present and displayed but is not enabled')
  return element
这在python脚本和交互控制台中都可以正常工作

但是,如果我在
if not元素之前输入回车符,则在控制台中,
if
之后的
raise
中会出现“意外缩进”错误,并且在代码中,函数似乎在
之后结束,除了:
(它不返回任何内容)


我认为回车在python代码中并不重要。我遗漏了什么吗?

回车在Python代码中并不重要,但它们在交互控制台中。如果在空行中按enter键,它将假定您已编写完正在处理的任何类/函数/循环,并尝试对其进行解释。

回车在Python代码中并不重要,但它们在交互控制台中。如果在空行中按enter键,它会假定您已经完成了编写正在处理的任何类/函数/循环,并尝试对其进行解释