import tensorflow as tf
state = tf.Variable(0,name='counter')#创建变量
#print state.name
one = tf.constant(1)#创建常量
new_value = tf.add(state,one)#加法
update = tf.assign(state,new_value)#重新分配
init = tf.initialize_all_variables()#must have if define variable
#在会话中操作
with tf.Session() as sess:
sess.run(init)
for _ in range(3):
sess.run(update)
print sess.run(state)