Daniel Mikulec
last month
Danielcountry asked

In float numbers, must I only use dots (.) to separate the decimal parts? Or can I use commas as well?

Udayan Shakya
Expert
last month
Udayan Shakya answered

Hello, Daniel. You can't use commas for float numbers in Python (you must use dot). This is because Python recognizes the dot as the standard way to indicate the fractional part of a number.

For example:

print(3.14)  # This is a float
print(2.5)   # This is also a float

Using a comma instead of a dot can lead to errors or unexpected behaviors. For instance:

# This will print 3 and 14 as separate numbers
print(3,14)

In this case, Python treats 3 and 14 as two separate arguments, so it would output them as 3 14 (two numbers), instead of recognizing them as a single float number.

Hope this helps! Let me know if you have more questions!

Python
This question was asked as part of the Learn Python Basics course.