Error: IndentationError: expected an indented block

Where?

  Python代码执行时候报这个错误

Why?

  Python代码具有严格缩进规范,默认规范为一层缩进为4个空格,但可以缩进至少一个空格,推荐按规范来,这个出错函数下下缩进错误

Way?

  检查缩进,修改正确

错误代码:

class Num(object):
def __init__(self, num):
self.num = num def __abs__(self):
# 缩进不正确
return abs(self.num) num = Num(-10)
print(abs(num))

正确代码:

class Num(object):
def __init__(self, num):
self.num = num def __abs__(self):
# 缩进正确
return abs(self.num) num = Num(-10)
print(abs(num))

  

Python-IndentationError: expected an indented block的更多相关文章

  1. [转]python问题:IndentationError:expected an indented block错误解决

    分类: python学习笔记2012-07-07 17:59 28433人阅读 评论(4) 收藏 举报 python语言 原文地址:http://hi.baidu.com/delinx/item/17 ...

  2. python问题:IndentationError:expected an indented block错误解决《转》

    python问题:IndentationError:expected an indented block错误解决 标签: python语言 2012-07-07 17:59 125145人阅读 评论( ...

  3. python问题:IndentationError:expected an indented block错误解决

    Python语言是一款对缩进非常敏感的语言,给很多初学者带来了困惑,即便是很有经验的Python程序员,也可能陷入陷阱当中.最常见的情况是tab和空格的混用会导致错误,或者缩进不对,而这是用肉眼无法分 ...

  4. Python问题1:IndentationError:expected an indented block

    Python语言是一款对缩进非常敏感的语言,给很多初学者带来了困惑,即便是很有经验的python程序员,也可能陷入陷阱当中.最常见的情况是tab和空格的混用会导致错误,或者缩进不对,而这是用肉眼无法分 ...

  5. python 中出现 “IndentationError: expected an indented block” 问题

    python 学习 在定义Python函数的时候如下 >>>def hello() . . .print "hello" 这样会报错的,报错如下: Indenta ...

  6. python问题:IndentationError:expected an indented block

    Python语言是一款对缩进非常敏感的语言,给很多初学者带来了困惑,即便是很有经验的Python程序员,也可能陷入陷阱当中.最常见的情况是tab和空格的混用会导致错误,或者缩进不对,而这是用肉眼无法分 ...

  7. python中IndentationError: expected an indented block错误的解决方法

    IndentationError: expected an indented block 翻译为IndentationError:预期的缩进块 解决方法:有冒号的下一行要缩进,该缩进就缩进

  8. IndentationError : expected an indented block

    IndentationError:在python的条件语句出现 expected an indented block问题 是指缩进问题,比如for循环里面的print前面需要四个空格. Python语 ...

  9. IndentationError:expected an indented block错误解决

    Python语言是一款对缩进非常敏感的语言,给很多初学者带来了困惑,即便是很有经验的Python程序员,也可能陷入陷阱当中.最常见的情况是tab和空格的混用会导致错误,或者缩进不对,而这是用肉眼无法分 ...

  10. IndentationError: expected an indented block错误

    Python语言是一款对缩进非常敏感的语言,给很多初学者带来了困惑,即便是很有经验的python程序员,也可能陷入陷阱当中.最常见的情况是tab和空格的混用会导致错误,或者缩进不对,而这是用肉眼无法分 ...

随机推荐

  1. springcloud高级

    第一章 负载均衡 Ribbon   (Spring Cloud 高级)   一. Ribbon 在微服务中的作用   1 什么是 Ribbon   1.Ribbon 是一个基于 Http 和 TCP ...

  2. opencv 截图并保存

    opencv 截图并保存(转载) 代码功能:选择图像中矩形区,按S键截图并保存,Q键退出. #include<opencv2/opencv.hpp> #include<iostrea ...

  3. 【Azure DevOps系列】Azure DevOps生成代码覆盖率

    前言 在做单元测试时,代码覆盖率可以作为我们衡量代码质量的一个指标,本章我们将使用Azure DevOps帮助我们生成代码覆盖率的结果.Azure DevOps构建管道还是具有代码覆盖率选项的,在Vi ...

  4. 手写Promise看着一篇就足够了

    目录 概要 博客思路 API的特性与手写源码 构造函数 then catch Promise.resolved Promise.rejected Promise.all Promise.race 概要 ...

  5. jQuery入口函数与JavaScript入口函数的区别

    jQuery  的入口函数是在  html  所有标签 (DOM) 都加载之后就会去执行 JavaScript  的  window.onload  时间是等到所有内容,包括外部图片之类的文件加载完成 ...

  6. SSM整合+WebUpload使用(spring+springmvc+mybatis+maven)

      SSM框架整合以及webupload的集成与使用 在项目中最近用到了webupload.js,也方方面面遇到了不少问题,比如上传文件前对表单参数校验,当校验失败不予提交,及在文件上传成功后,选择同 ...

  7. Agumater 增加基本数据上传下载能力

  8. .NET实现可交互的WINDOWS服务(转载自CSDN"烈火蜓蜻")

    Windows 服务应用程序在不同于登录用户的交互区域的窗口区域中运行.窗口区域是包含剪贴板.一组全局原子和一组桌面对象的安全对象.由于 Windows 服务的区域不是交互区域,因此 Windows ...

  9. Python多行缩进反向缩进快捷键

    1.Python增加缩进快捷键:Ctrl+Alt+] 或tab键或shift+tab键 2.Python减少缩进快捷键:Ctrl+Alt+[ 

  10. selenium常用webdriver api汇总

    1.driver.current_url:用于获得当前页面的URL 2.driver.title:用于获取当前页面的标题 3.driver.page_source:用于获取页面html源代码 4.dr ...