#通过变量赋值输出1-10
import tensorflow.compat.v1 as tf
tf.disable_eager_execution()
value = tf.Variable(0,name='value')
#定义一个常量
one = tf.constant(1)
#实现value+1
new_value = tf.add(value,one)
update_value = tf.assign(value,new_value)
#变量初始化
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
for _ in range(10):
sess.run(update_value)
print(sess.run(value))
谢谢各位观看~