9951 explained code solutions for 126 technologies


python-tensorflowHow do I create a "Hello World" program using Python and TensorFlow?


This "Hello World" program using Python and TensorFlow will print "Hello World" to the console.

import tensorflow as tf

hello = tf.constant('Hello, World!')
sess = tf.Session()
print(sess.run(hello))

Output example

b'Hello, World!'

The code consists of the following parts:

  1. Import TensorFlow as tf: This is done using import tensorflow as tf.
  2. Create a constant string hello with value Hello, World!: This is done using hello = tf.constant('Hello, World!').
  3. Create a session sess: This is done using sess = tf.Session().
  4. Print hello to the console: This is done using print(sess.run(hello)).

Helpful links

Edit this code on GitHub