首页 \ 问答 \ 什么是飞客?

什么是飞客?

与飞信是什么关系?
更新时间:2022-01-04 14:01

最满意答案

你学过编程吗?一般语言都是通过{}来标识代码块的,而在python中,是通过缩进来识别代码块的。我一个一个的回答你的问题。
缩进几个空格或者tab都是可以的,只要你保持一致就可以。不过为了别人阅读方便,还是用tab或者4个空格比较好。
行开头的空格才算缩进。
当需要书写子代码块时,用缩进。
你要知道缩进的用途,它是用来标识不同的代码块的,通过不同的缩进来判断代码行之间的关系。

if,while,for,def行之后的行首的空格都是缩进。

其他回答

类似c语言风格的缩进
set cindent
智能缩进:每一行都和前一行有相同的缩进量,
同时这种缩进形式能正确的识别出花括号,当遇到右花括号(}),
则取消缩进形式。此外还增加了识别c语言关键字的功能。
如果一行是以#开头的(比如宏),那么这种格式将会被特殊对待而不采用缩进格式
set smartindent
for python programmers
autocmd filetype python set textwidth=79  pep-8 friendly
把输入的tab自动转换成空格,python用户必用~
set expandtab
一个tab键占据4个空格
set tabstop=4
一开始,插入的就是4个空格,此时一旦你再按下一次tab,这次的四个空格就会和上次的四个空格组合起来变成一个制表符
set softtabstop=4
每一级自动缩进的空格数
set shiftwidth=4
根据文件类型设定缩进,覆盖掉默认的~
autocmd filetype python setlocal tabstop=4 shiftwidth=4 softtabstop=4 textwidth=79
另外即使配置如此 ,python的缩进也并不是很理想。
比较好的选择是再使用一个插件 hynek/vim-python-pep8-indent

相关问答

更多
  • 额,怎么说呢,python2.x版本tab的缩进和空格没有严格区分 python3.x开始4个空格表示一个缩进,不允许tab缩进了。
  • 这样就可以啦 你去下载pythonwin,它会告诉你错误在哪一行, 缩进技巧最好是每块代码以4个空格为佳
  • 交互模式在使用块语句(if, while, try)时,在结束块语句时,要输入额外的回车的。交互模式只会一个命令一个命令地执行,块语句视为一个语句。 >>> if true: ... print "hahahahahaha" (回车) print "hehe" 想要一次执行,必须写成一个脚本,以.py后缀命名(其实用什么后缀都可以)。然后在命令行执行: python mytest.py 望采纳!
  • 你学过编程吗?一般语言都是通过{}来标识代码块的,而在python中,是通过缩进来识别代码块的。我一个一个的回答你的问题。 缩进几个空格或者tab都是可以的,只要你保持一致就可以。不过为了别人阅读方便,还是用tab或者4个空格比较好。 行开头的空格才算缩进。 当需要书写子代码块时,用缩进。 你要知道缩进的用途,它是用来标识不同的代码块的,通过不同的缩进来判断代码行之间的关系。 if,while,for,def行之后的行首的空格都是缩进。
  • 因为在python中各个语句间没有分隔符,所以用缩进来切分成不同的代码块
  • Python 缩进[2021-11-24]

    你在IDLE中每次只能输入一个代码块,比如一个def,for,if,while代码块。 你最后的block0是和if平级还是if内部的? 如果是平级,那你这种写法就是错的,因为if已经是一个代码块了,block0是第二个代码块,这么写是不对的。 如果是内部的,那你应该让它和block1的缩进相同。 从你的意思看,你是想让它和if平级吧?那你需要把if和block0写到一个函数中,或者写到py文件中再运行
  • python的缩进问题[2024-01-29]

    你用什么编辑器?如果是IDLE的话,选中需要缩进的行,按菜单Edit->Indent Region就可以了。 大多数代码编辑器也有类似的功能。如果找不到,可以先用IDLE编辑好了保存一下。
  • python缩进问题[2021-09-07]

    可能是TAB跟空格的问题,解决方案: 1. 把缩进都删除; 2. 每级缩进只用一个空格,这样问题是解决了; 3. 最好的建议是File--New Window,新建一个py文件,在这个里面输入代码。
  • def find_the_atom(filename,r,n): with open(filename) as file: sery=atom_generator(file) atom=next(sery,None) while atom and atom.Model!=r: atom=next(sery,None) if atom: while atom and atom.number!=n: atom=next(sery,None) if atom: return atom else: print('该 ...
  • 报错在第三句,print 'End!'处出现,if语句块写完后,ctrl+d可以看到if语句的打印结果,然后再写print ‘End!',否则像你这么写的话,默认最后一句print也在语句块内,但是没有做缩进,所以报错了。

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)