Hacker News new | past | comments | ask | show | jobs | submit login

I suppose that print statement was just a silly example, but just in case this may be of use to anyone, note that you can pass multiple arguments to print and they will be printed space-separated, each converted to a str, so you will (practically) never run into type errors.

print(str, int)




True, that's a problem I don't have anymore but it's a quick and understandable example of a mistake that I think lots of people had made before.

Instead of a comma I would actually recommend f-strings, which are python's string interpolation. The only downside is that the code within the f-strings I think have even less prechecking.

https://www.python.org/dev/peps/pep-0498/

Example: print(f"There are {len(lights)} lights!")


I absolutely agree that f-strings are excellent for formatting, but I don't quite understand why you would use formatting in a regular print statement, when you could just stick to the commas and let the concatenation happen naturally in the output buffer?

print("There are", len(lights), "lights!")




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: