例1
>>>p = lambda x,y:x+y
>>>p(3,4)
7
例2
import tensorflow as tf
tf.reset_default_graph()
x = tf.constant(10)
y = tf.constant(5)
a=2
b=3
z = tf.multiply(a, b)
result = tf.cond(x < y, lambda: tf.add(x, z), lambda: tf.square(y))
with tf.Session() as sess:
print(sess.run(result))
输出
25