It is part of a begginer online tutorial and I am required to use string formatting as you can probably tell. I do not know how to call from a specific part of data. I keep getting syntax errors like this \/File "<string>", line 3 print format_string " %s %s, Your current balence is %d$." % data ^ SyntaxError: invalid syntax

It is part of a begginer online tutorial and I am required to use string formatting as you can probably tell. I do not know how to call from a specific part of data. I keep getting syntax errors like this \/File "<string>", line 3 print format_string " %s %s, Your current balence is %d$." % data ^ SyntaxError: invalid syntax

Here's the general method for string formatting in 2.x; for version 3, someone else will have to answer.

You insert the placeholders (%s) in the string you want, then the %, followed by the values you want to insert in parentheses. If there is only one value to insert, then the parentheses are optional. The number of placeholders and the number of values must match. Your specific problem would have 3 "%" placeholders in your string, and 3 values in the parentheses.

The "%s" indicates that you are inserting a string variable. You can use "%f" for a float variable (like a dollar amount), or "%i" for an integer, in addition to "%s". Look in the Python docs for more details about other value types you can insert.

Please post complete tracebacks in code tags. It looks from what you posted that the syntax error is at the beginning of the line. That is generally a sign that the syntax error is on the previous line, where you forgot to close a parentheses or a bracket. However, I expect it's because you have a variable (format_string) next to a string literal ("Hello ..." without an operator in between.

Complete tracebacks with the code that actually caused the error can help us pinpoint the problem much better.

Due to the reasons discussed here we will be moving to python-forum.io on October 1st, 2016.This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.