import tensorflow as tf data1 = tf.constant(25,dtype='int16') data2 = tf.Variable(3,name='data2') print(data1) print(data2) # sess = tf.Session() # init = tf.global_variables_initializer() # sess.run(init) # print(sess.run(data2)) sess = tf.Session() #创建session会话 init = tf.global_variables_initializer() #变量需要初始化 with sess: #自动关闭session sess.run(init) #运行init print(sess.run(data2))