To write flask code you must import flask.


from flask import Flask

Then create an app for flask.


app = Flask(__name__)

Then define your application route and action for the route in function.


@app.route("/")
def hello():
    return "Hello World!"

Then run the app.


if __name__ == "__main__":
    app.run()

Full code:


from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

Save the above code as python file.And execute the file.


Python filename.py

It will return an url like below.

http://127.0.0.1:5000

or

http://localhost:5000

Then browse the url in browser . The hello world will be displayed.