from flask import Flask
app = Flask(__name__)
@app.route('/')
def remove_last_character():
original_string = "Hello World"
modified_string = original_string[:-1]
return f"Original String: {original_string}<br>Modified String: {modified_string}"
if __name__ == '__main__':
app.run(debug=True)
- Import the
Flask
class from the flask
module. - Create a Flask application instance.
- Define a route
'/'
using the @app.route()
decorator. - Create a function
remove_last_character()
to handle requests to this route. - Initialize an
original_string
variable with the value "Hello World"
. - Use slicing (
[:-1]
) to create a modified_string
that excludes the last character of the original_string
. - Return a string displaying the original string and the modified string in the browser.
- Start the Flask application in debug mode if the script is executed directly.