简体   繁体   English

Python IDLE中的缩进问题

[英]Indention issue in Python IDLE

IDLE config is set as 空闲配置设置为

indentation width - 4 spaces
key set - IDLE classic windows
at startup - Open shell window
paragraph reformat width (in characters) - 70

I open up python IDLE and I am in the shell window. 我打开python IDLE,我在外壳程序窗口中。 I click file > new file. 我单击文件>新文件。 I am now in the text editor. 我现在在文本编辑器中。 I write a line of code. 我写了一行代码。 It doesnt matter what the syntax is. 语法是什么都没关系。 When i push the "enter" button on my keyboard. 当我按下键盘上的“输入”按钮时。 Instead of dropping down to the next line and being in the proper spot. 而不是下降到下一行并处于适当的位置。 The little thing that blinks to show you where your at on the page is near the middle of the page... 闪烁的小东西向您显示页面上您在页面中间的位置...

number = float(input('what is your number? ')
               name = input('what is your name? ')


name = input('what is your name?')
               this is where it indents to
               it doesnt matter the syntax

number = int(input('what is your number?')
               if number > 5
               print (""" I am only using the enter key to
go to the next line""")
               else:
               print('this is what it does')

even if double spaced, should it not look like this? 即使是双倍行距,它也不应该是这样吗?

number = int(input('what is your number?')
    if number < 5555
        print (' helloe')
    else:
        print('..............')

You need to make sure that you have your parenthesis matched. 您需要确保您的括号匹配。 In your example you are missing one ')' at the first line. 在您的示例中,第一行缺少一个')'。

number = float(input('what is your number? ') ) # this last parenthesis is missing in your example
name = input('what is your name? ')

The code would probably not run. 该代码可能不会运行。 You should make it a habit of always writing the closing parenthesis directly when you start an expression. 您应该养成在开始表达式时始终直接写右括号的习惯。 In that way you know you've got them matched. 这样,您就知道它们已经匹配。

The reason why you get strange indentation is because without the closing parenthesis the editor thinks that the next line is part of the previous expression, which is your 之所以会产生奇怪的缩进,是因为在没有右括号的情况下,编辑器认为下一行是上一个表达式的一部分,即

number = float(input('what is your number? ')
               # notice how the indentation is right below
               # the opening parenthesis
               )
name = input('what is your name? '
             # notice how this indentation has a
             # a different position
             )

You have mistake on: 您在以下方面有误:

               if number > 5

Correct is: 正确的是:

               if number > 5:

and you wrote: 并且您写道:

               name = input('what is your name? ')

but you should write: 但您应该写:

name = input('what is your name? ')

without all that spaces. 没有所有的空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM