Python Forum
Understanding formatting
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Understanding formatting
#1
Hi!

I found a script online that uses the website ipinfo.io to deliver some information about the users IP adress. I'm trying to figure out what this line means:
print ('IP : {4} \nRegion : {1} \nCountry : {2} \nCity : {3} \nOrg : {0}'.format(org,region,country,city,IP))
In context of this here script:

import re
import json
from urllib.request import urlopen

url = 'http://ipinfo.io/json'
response = urlopen(url)
data = json.load(response)

IP=data['ip']
org=data['org']
city = data['city']
country=data['country']
region=data['region']

print ('Your IP detail\n ')
print ('IP : {4} \nRegion : {1} \nCountry : {2} \nCity : {3} \nOrg : {0}'.format(org,region,country,city,IP))
Specifically, what exactly do the numbers represent inbetween the variables? How does the .format do its thing?

Thanks a lot in advance.
Reply


Messages In This Thread
Understanding formatting - by mickandralphscrier - Nov-14-2018, 04:45 PM
RE: Understanding formatting - by Larz60+ - Nov-14-2018, 04:51 PM
RE: Understanding formatting - by j.crater - Nov-14-2018, 04:59 PM
RE: Understanding formatting - by Larz60+ - Nov-14-2018, 06:22 PM
RE: Understanding formatting - by j.crater - Nov-14-2018, 06:34 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020