how we load 12.0.0.0 in a python dictionary

Recommended Answers

All 5 Replies

Do you mean as an IP address? Need a little more specifics than that...

dicts require an identifier (usuall a string), and the object(s) that the identifier refers to... so...

ip_addys = dict()
ip_addys['first_ip'] = 12.0.0.0

should probably work... There are other ways to directly insert into a dict as a key=>value pair, but the simplest way is to use the above (in my opinion).

You must also convert the ip number to normal number or keep it as string. I have posted as one of my first Code Snppets functions for the conversion.

i tried the following code.

ip_addys = dict()ip_addys['first_ip'] = 12.0.0.0

but it shows a syntax error occured in 12.0.0.0

12.0.0.0 is not a valid python literal. Use "12.0.0.0" which creates a str instance.

yeah, sorry... it would need to be a string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.