What does % do to strings in Python? [closed]Meanings of percent sign(%)What does the modulus symbol do here?What does this code “%.8f”% do in python?What does percentage sign do in python if not working as a moduleHow to use % symbol correctlyPython - open(filename(n))What is the difference between String and string in C#?What are metaclasses in Python?What does the “yield” keyword do?Does Python have a ternary conditional operator?How to substring a string in Python?What is the !! (not not) operator in JavaScript?What is the “-->” operator in C++?How to check whether a string contains a substring in JavaScript?Does Python have a string 'contains' substring method?Reference — What does this symbol mean in PHP?
Has a commercial or military jet bi-plane ever been manufactured?
How do I, as a DM, handle a party that decides to set up an ambush in a dungeon?
Copy previous line to current line from text file
Start job from another SQL server instance
As a GM, is it bad form to ask for a moment to think when improvising?
How to pass hash as password to ssh server
Why is my arithmetic with a long long int behaving this way?
Handling Null values (and equivalents) routinely in Python
My first c++ game (snake console game)
Is there a word for food that's gone 'bad', but is still edible?
Dangerous workplace travelling
Which sphere is fastest?
Mug and wireframe entirely disappeared
Endgame puzzle: How to avoid stalemate and win?
Why is "breaking the mould" positively connoted?
Why do people keep telling me that I am a bad photographer?
What was Bran's plan to kill the Night King?
History of the kernel of a homomorphism?
Can my 2 children, aged 10 and 12, who are US citizens, travel to the USA on expired American passports?
Gerrymandering Puzzle - Rig the Election
How should I tell my manager I'm not paying for an optional after work event I'm not going to?
Why did WWI include Japan?
Voltage Balun 1:1
Is disk brake effectiveness mitigated by tyres losing traction under strong braking?
What does % do to strings in Python? [closed]
Meanings of percent sign(%)What does the modulus symbol do here?What does this code “%.8f”% do in python?What does percentage sign do in python if not working as a moduleHow to use % symbol correctlyPython - open(filename(n))What is the difference between String and string in C#?What are metaclasses in Python?What does the “yield” keyword do?Does Python have a ternary conditional operator?How to substring a string in Python?What is the !! (not not) operator in JavaScript?What is the “-->” operator in C++?How to check whether a string contains a substring in JavaScript?Does Python have a string 'contains' substring method?Reference — What does this symbol mean in PHP?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have failed to find documentation for the operator % as it is used on strings in Python. What does this operator do when it is used with a string on the left hand side?
python string documentation operators
closed as off-topic by Mogsdad, Robert Columbia, AdrianHHH, kayess, FrankerZ Jan 15 '18 at 16:03
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Mogsdad, Robert Columbia, AdrianHHH, kayess, FrankerZ
add a comment |
I have failed to find documentation for the operator % as it is used on strings in Python. What does this operator do when it is used with a string on the left hand side?
python string documentation operators
closed as off-topic by Mogsdad, Robert Columbia, AdrianHHH, kayess, FrankerZ Jan 15 '18 at 16:03
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Mogsdad, Robert Columbia, AdrianHHH, kayess, FrankerZ
add a comment |
I have failed to find documentation for the operator % as it is used on strings in Python. What does this operator do when it is used with a string on the left hand side?
python string documentation operators
I have failed to find documentation for the operator % as it is used on strings in Python. What does this operator do when it is used with a string on the left hand side?
python string documentation operators
python string documentation operators
edited yesterday
BeeOnRope
27k885186
27k885186
asked Aug 6 '09 at 11:29
Ram RachumRam Rachum
26.5k63185302
26.5k63185302
closed as off-topic by Mogsdad, Robert Columbia, AdrianHHH, kayess, FrankerZ Jan 15 '18 at 16:03
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Mogsdad, Robert Columbia, AdrianHHH, kayess, FrankerZ
closed as off-topic by Mogsdad, Robert Columbia, AdrianHHH, kayess, FrankerZ Jan 15 '18 at 16:03
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Mogsdad, Robert Columbia, AdrianHHH, kayess, FrankerZ
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
It's the string formatting operator. Read up on string formatting in Python.
format % values
Creates a string where format
specifies a format and values
are the values to be filled in.
add a comment |
It applies printf-like formatting to a string, so that you can substitute certain parts of a string with values of variables.
Example
# assuming numFiles is an int variable
print "Found %d files" % (numFiles, )
See the link provided by Konrad
add a comment |
The '%' operator is used for string interpolation. Since Python 2.6 the String method "format" is used insted. For details see http://www.python.org/dev/peps/pep-3101/
add a comment |
Note that starting from Python 2.6, it's recommended to use the new str.format()
method:
>>> "The sum of 1 + 2 is 0".format(1+2)
'The sum of 1 + 2 is 3'
If you are using 2.6, you may want to keep using %
in order to remain compatible with older versions, but in Python 3 there's no reason not to use str.format()
.
2
format() is really powerful too. You can use named tags like "Hello planet".format(planet='earth')
– aehlke
Aug 6 '09 at 14:27
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's the string formatting operator. Read up on string formatting in Python.
format % values
Creates a string where format
specifies a format and values
are the values to be filled in.
add a comment |
It's the string formatting operator. Read up on string formatting in Python.
format % values
Creates a string where format
specifies a format and values
are the values to be filled in.
add a comment |
It's the string formatting operator. Read up on string formatting in Python.
format % values
Creates a string where format
specifies a format and values
are the values to be filled in.
It's the string formatting operator. Read up on string formatting in Python.
format % values
Creates a string where format
specifies a format and values
are the values to be filled in.
edited Nov 29 '16 at 17:48
phyatt
14.5k23254
14.5k23254
answered Aug 6 '09 at 11:30
Konrad RudolphKonrad Rudolph
406k1017961042
406k1017961042
add a comment |
add a comment |
It applies printf-like formatting to a string, so that you can substitute certain parts of a string with values of variables.
Example
# assuming numFiles is an int variable
print "Found %d files" % (numFiles, )
See the link provided by Konrad
add a comment |
It applies printf-like formatting to a string, so that you can substitute certain parts of a string with values of variables.
Example
# assuming numFiles is an int variable
print "Found %d files" % (numFiles, )
See the link provided by Konrad
add a comment |
It applies printf-like formatting to a string, so that you can substitute certain parts of a string with values of variables.
Example
# assuming numFiles is an int variable
print "Found %d files" % (numFiles, )
See the link provided by Konrad
It applies printf-like formatting to a string, so that you can substitute certain parts of a string with values of variables.
Example
# assuming numFiles is an int variable
print "Found %d files" % (numFiles, )
See the link provided by Konrad
answered Aug 6 '09 at 11:38
Diaa SamiDiaa Sami
2,7292026
2,7292026
add a comment |
add a comment |
The '%' operator is used for string interpolation. Since Python 2.6 the String method "format" is used insted. For details see http://www.python.org/dev/peps/pep-3101/
add a comment |
The '%' operator is used for string interpolation. Since Python 2.6 the String method "format" is used insted. For details see http://www.python.org/dev/peps/pep-3101/
add a comment |
The '%' operator is used for string interpolation. Since Python 2.6 the String method "format" is used insted. For details see http://www.python.org/dev/peps/pep-3101/
The '%' operator is used for string interpolation. Since Python 2.6 the String method "format" is used insted. For details see http://www.python.org/dev/peps/pep-3101/
answered Aug 6 '09 at 11:31
lutz
add a comment |
add a comment |
Note that starting from Python 2.6, it's recommended to use the new str.format()
method:
>>> "The sum of 1 + 2 is 0".format(1+2)
'The sum of 1 + 2 is 3'
If you are using 2.6, you may want to keep using %
in order to remain compatible with older versions, but in Python 3 there's no reason not to use str.format()
.
2
format() is really powerful too. You can use named tags like "Hello planet".format(planet='earth')
– aehlke
Aug 6 '09 at 14:27
add a comment |
Note that starting from Python 2.6, it's recommended to use the new str.format()
method:
>>> "The sum of 1 + 2 is 0".format(1+2)
'The sum of 1 + 2 is 3'
If you are using 2.6, you may want to keep using %
in order to remain compatible with older versions, but in Python 3 there's no reason not to use str.format()
.
2
format() is really powerful too. You can use named tags like "Hello planet".format(planet='earth')
– aehlke
Aug 6 '09 at 14:27
add a comment |
Note that starting from Python 2.6, it's recommended to use the new str.format()
method:
>>> "The sum of 1 + 2 is 0".format(1+2)
'The sum of 1 + 2 is 3'
If you are using 2.6, you may want to keep using %
in order to remain compatible with older versions, but in Python 3 there's no reason not to use str.format()
.
Note that starting from Python 2.6, it's recommended to use the new str.format()
method:
>>> "The sum of 1 + 2 is 0".format(1+2)
'The sum of 1 + 2 is 3'
If you are using 2.6, you may want to keep using %
in order to remain compatible with older versions, but in Python 3 there's no reason not to use str.format()
.
edited Aug 6 '09 at 17:39
answered Aug 6 '09 at 12:40
Bastien LéonardBastien Léonard
46.3k177091
46.3k177091
2
format() is really powerful too. You can use named tags like "Hello planet".format(planet='earth')
– aehlke
Aug 6 '09 at 14:27
add a comment |
2
format() is really powerful too. You can use named tags like "Hello planet".format(planet='earth')
– aehlke
Aug 6 '09 at 14:27
2
2
format() is really powerful too. You can use named tags like "Hello planet".format(planet='earth')
– aehlke
Aug 6 '09 at 14:27
format() is really powerful too. You can use named tags like "Hello planet".format(planet='earth')
– aehlke
Aug 6 '09 at 14:27
add a comment |