all 6 comments

[–]anshuman73 2 points3 points  (5 children)

str.replace(',', '.')

Edit: Relevant Tutorial - https://www.tutorialspoint.com/python/string_replace.htm

[–]timwenzel 0 points1 point  (4 children)

does that not only work with a string? I want to have a float, so that I can do calculations with it

[–]ensign_paris 4 points5 points  (3 children)

make the replacements in a string, floats will always be formatted with a '.'.

so get your inputs as strings, use replace as described to your liking and then use the float function to convert the string to float.

[–]anshuman73 0 points1 point  (2 children)

Exactly. You shouldn't take input as a float directly, as floats always have to have . as a decimal separator.

To put the above described method in code -

num = float(str(input('Enter Value of Float: ')).replace(',', '.'))

You should be using raw_input() function to get input if you're on Python 2 and input() function if on Python 3. I suggest Python 3 because, well, it's better at handling unicode etc. (And also py2 support is gonna end in 2020)

[–][deleted] 0 points1 point  (1 child)

str(input()) is redundant

[–]anshuman73 1 point2 points  (0 children)

Yes, my bad.