【问题标题】:Syntax Error with <> [duplicate]<> 语法错误 [重复]
【发布时间】:2015-12-30 01:38:38
【问题描述】:

我正在尝试完成这项任务:

这就是我所拥有的,我在 >

上遇到语法错误

粘贴代码:

# Specify where the input and output file is

InputFile = open('C:\Python\unsorted_fruits.txt', 'r')
OutputFile = open('C:\Python\sorted_fruits.txt', 'w')

# Read the input file

Fruits = InputFile.readlines()

# Sort the items in the list
Fruits.sort()

# Remove the blank lines and write the file
for fruit in Fruits:
    if fruit <>"\n":    # if fruit is blank, skip the write
        OutputFile.write(fruit) # otherwise write the fruit to the output file


# Close the input and output file
InputFile.close()
OutputFile.close()

【问题讨论】:

  • if fruit &lt;&gt;"\n": 你到底在做什么?
  • 哦,是这样的吗?什么语言使用它?
  • &lt;&gt; 不像 != 的某些已弃用语法

标签: python syntax-error


【解决方案1】:

只需将“”替换为“!=”,因为“”在python3中已弃用,可以用作“!=”。

【讨论】:

  • &lt;&gt;曾经在 Python 中使用过吗? o_O 我在 BASIC 之外的任何地方都没有见过它。
猜你喜欢
  • 2016-07-12
  • 2023-03-05
  • 2011-01-22
  • 2016-03-01
  • 1970-01-01
  • 2015-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多