import tensorflow as tf sess = tf.Session() #创建会话 a = tf.constant(3) b = tf.constant(5) #常量数据 c = tf.Variable(9) # 加减乘除操作 myadd = tf.add(a,b) mysub = tf.subtract(a,b) mymul = tf.multiply(a,b) mydi = tf.divide(a,b) vadd = tf.add(a,c) datacopy = tf.assign(c,vadd) #赋值方法 init = tf.global_variables_initializer() with sess: sess.run(init) print(sess.run(myadd)) print(sess.run(mysub)) print(sess.run(mymul)) print(sess.run(mydi)) print(sess.run(datacopy)) print(datacopy.eval()) #tensor.eval()另外一种运行方法