Linked Questions

52 votes
6 answers
168k views

This works: print "Hello World%s" %"!" But this doesn't print "Hello%20World%s" %"!" the error is ValueError: unsupported format character 'W' (0x57) at index 8 I am using Python 2.7. Why would I ...
highBandWidth's user avatar
41 votes
6 answers
127k views

I've made a little script to calculator percent; however, I wish to actually include the % within the message printed... Tried this at the start - didn't work... oFile.write("Percentage: %s%"...
19 votes
8 answers
26k views

I am trying to build a format string with lazy argument, eg I need smth like: "%s \%s %s" % ('foo', 'bar') # "foo %s bar" how can i do this?
Anycorn's user avatar
  • 51.9k
10 votes
1 answer
57k views

I'm trying to understand the following Python quine: s = 's = %r\nprint(s%%s)' print(s%s) In particular, I'm having trouble finding any info about that %% part. Anyone know what that does exactly, in ...
4 votes
4 answers
2k views

I am trying to append % in a string using string formats. I am trying to get the below output: a : [" name like '%FTa0213' "] Try 1 : a = [ ] b = {'by_name':"FTa0213"} a.append(" name like "%" %s'...
2 votes
4 answers
13k views

I am experimenting some string outputs and I came across something that throws an error when printing x = "ll=%s%2C%20%s" % ("lat", "lng") The syntax above throws an error: ValueError: unsupported ...
2 votes
2 answers
13k views

How do you make the following code work? example = "%%(test)%" % {'test':'name',} print example Where the desired output is "%name%" Thanks
6 votes
3 answers
14k views

I am trying to print a line with a with a float formatter to 2 decimal points like this: print "You have a discount of 20% and the final cost of the item is'%.2f' dollars." % price But when I do ...
-2 votes
1 answer
13k views

According to python 3 document, the string formating "%%" means "a perncet sign". Following code is an example: "%g%%" % 10.34 == "10.34%" I am not sure what does this "%g" mean here, I suspect it ...
-2 votes
2 answers
4k views

I came across a problem when I was learning python. print('test%d, %.2f%%' % (1,1.4)) however, it has an error. ValueError: incomplete format But if I execute like this: print('test%d, %.2f%%' % (1,...
5 votes
1 answer
2k views

I'm looking for a way to perform partial string formatting in Python logging formatters. When trying to define a formatter the following way: formatter = logging.Formatter('[num-%d] %(levelname)s %(...
3 votes
2 answers
346 views

I have a string that contains a % that I ALSO want to use %s to replace a section of that string with a variable. Something like name = 'john' string = 'hello %s! You owe 10%.' % (name) But when I ...
kroe761's user avatar
  • 3,564
0 votes
2 answers
142 views

Suppose I have a print statement in python as given : print "components required to explain 50% variance : %d" % (count) This statement gives a ValuError, but if I have this print statement : print "...
Jarvis's user avatar
  • 8,602
0 votes
4 answers
297 views

I want to execute a git command, in shell it is as below: $ git log v2.6.38..v2.6.38-rc8 --pretty=format:%s%n%n the --pretty=format:%s%n%n is to say only show the commit subject message, and every ...
mike's user avatar
  • 1,147
-2 votes
1 answer
90 views

I would like the output to be this I'm using '%s' to print this out: hello! My code: print "I'm using %s to print this out: %s" % "hello!" This returns an error.

15 30 50 per page
1
2 3