PyCharm 提示PEP 8: E302 expected 2 blank lines, found 1

使用pycharm编写python程序的时候,总会在def function()的时候,出现如下问题:

PEP 8: E302 expected 2 blank lines, found 1

造成此问题原因:在声明函数的那一行的上方必须有两行的空行,否则便出现这个情况。

eg:

# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.


def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


def print_string():
    # 字符串声明:单引号与双引号是等价
    name1 = 'Hi Python3'
    print(name1)
    name2 = "Hi Python3"
    print(name2)
    # 字符串声明:三引号包含多行文字的字符串
    name3 = """Hi
        Python3"""
    print(name3)


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('PyCharm')
    # 整数相加
    print(2 + 2)
    # 浮点数相加
    print(2.0 + 2.5)
    # 整数与浮点数相加
    print(2 + 2.5)
    # 变量赋值
    a = 10
    print(a)
    # 字符串声明函数
    print_string()
# See PyCharm help at https://www.jetbrains.com/help/pycharm/

你可能感兴趣的:(python,问题异常)