0

So I have this code in C#:

double latitude = 0.323 //Some random value for SO
double longitude = 0.535 //Some random value for SO
string result = string.Format("{0}, {1}",
            latitude.ToString(CultureInfo.InvariantCulture.NumberFormat),
            longitude.ToString(CultureInfo.InvariantCulture.NumberFormat));

And I like to convert that into Python code, problem is, I have no idea what NumberFormat does in this context and how I convert that into Python code.

Could anyone explain to me what the NumberFormat does in this case? Also, I'm assuming {0} and {1} means the first and second value entered after the comma?

I'm not asking what it does in C#, I'm asking if it can be done in Python and how.

KvdB
  • 19
  • 6
  • 1
    Python by default uses the `C` locale (equivalent of InvariantCulture), so there is no need to worry about that unless you changing the locale with the `locale` module. `'{}, {}'.format(latitude, longitude)` will do fine in Python, see the [Python format string syntax](https://docs.python.org/3/library/string.html#formatstrings), which is heavily based on the C# syntax. – Martijn Pieters Oct 05 '16 at 14:24
  • Thank you for the information! Does the {} just fill in the values in order? Why not just use ''.format(latitude, longitude) ? – KvdB Oct 05 '16 at 14:38
  • Yes, the default is to auto-number slots. Without `{}` slots, where would the values go? And what about the comma and space? – Martijn Pieters Oct 05 '16 at 14:39

0 Answers0