我是靠谱客的博主 柔弱大米,这篇文章主要介绍assert的用法,现在分享给大家,希望可以做个参考。

assert用于断言,也就是判断一下一个表达式的的对与错,或者是一数字或者布尔类型的数据。如果是对的,那就继续执行下面程序,反正出现断言错误的标记,AssertionError

例如:

import tensorflow as tf;    
import numpy as np;    
import matplotlib.pyplot as plt;    
  
assert 1

print 4
输出:

4

import tensorflow as tf;    
import numpy as np;    
import matplotlib.pyplot as plt;    
  
assert True

print 4
输出:

4

import tensorflow as tf;    
import numpy as np;    
import matplotlib.pyplot as plt;    
  
assert 0

print 4
输出:

AssertionError

import tensorflow as tf;    
import numpy as np;    
import matplotlib.pyplot as plt;    
  
assert False

print 4
输出:

AssertionError

# -*- coding: utf-8 -*-
import tensorflow as tf;    
import numpy as np;    
import matplotlib.pyplot as plt;    
  
assert 1 > 0


print 4

输出:

4

最后

以上就是柔弱大米最近收集整理的关于assert的用法的全部内容,更多相关assert内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(127)

评论列表共有 0 条评论

立即
投稿
返回
顶部