Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJari Koopman
Python Web Development Techdegree Graduate 29,349 Pointsprintf or println
In the video of Exceptions (Java, Craig Dennis) there is the part about when you put in too many PEZ. The following is written:
System.out.println(βWhoa there!); System.out.printf(βThe error was: %s\nβ, iae.getMessage());
I think somewhere in the course I missed something, cause I don't get the difference between println and printf. So is there anyone who can tell me the difference and when you use println and when printf?? Thank you!
1 Answer
Steve Hunter
57,712 PointsHi Jari,
printf
prints a formatted string - that's why you can use %s and a load of other formatters within your output string.
println
just prints out some text with a new line.
I hope that helps,
Steve.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsHere is some helpful documentation on how the formatter works.
Jari Koopman
Python Web Development Techdegree Graduate 29,349 PointsJari Koopman
Python Web Development Techdegree Graduate 29,349 PointsThank you Steve, I get it!