1

I'm trying to develop a maco in python. I need a method that changes the URI given in the input variables.

For instance, in www.(variable).com I need to change the URL www.1.com to www.2.com

1
  • 3
    You can use F-Strings. They will replace the variable on the string. And also when opening any question in SO, follow this guide to provide a good question Commented Jan 25, 2021 at 11:08

2 Answers 2

1

You can use formatted strings like this:

variable = 1
url = f"www.{variable}.com"
Sign up to request clarification or add additional context in comments.

1 Comment

I really appreciate it
0

You could store your list of names in a list and then interpolate the variable into the f-string like:

names = ['google', 'amazon', 'microsoft']
for name in names:
    print(f"www.{name}.com")

OUTPUT

www.google.com
www.amazon.com
www.microsoft.com

1 Comment

I really appreciate it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.