Python has a %
operator for this.
>>> a = 5 >>> b = "hello" >>> buf = "A = %d\n , B = %s\n" % (a, b) >>> print buf A = 5 , B = hello >>> c = 10 >>> buf = "C = %d\n" % c >>> print buf C = 10
See this reference for all supported format specifiers.
You could as well use format
:
>>> print "This is the {}th tome of {}".format(5, "knowledge") This is the 5th tome of knowledge
Related Posts:
- working of \n in python [duplicate]
- How to remove punctuation in python?
- Python: TypeError: cannot concatenate ‘str’ and ‘int’ objects
- How to get the filename without the extension from a path in Python?
- n-grams in python, four, five, six grams?
- Alphabet range in Python
- How do I lowercase a string in Python?
- How do I get a substring of a string in Python?
- Changing one character in a string
- How to read a file line-by-line into a list?
- What is lexicographical order?
- strip(char) on a string
- How to convert list to string [duplicate]
- Converting integer to string in Python
- Reverse a string in Python
- ValueError: could not convert string to float: id
- Regex not operator
- Print string to text file
- Best way to convert string to bytes in Python 3?
- Best way to convert string to bytes in Python 3?
- Does Python have a string ‘contains’ substring method?
- Extract substring in Bash
- How do I append one string to another in Python?
- How can I split and parse a string in Python?
- How to read a text file into a string variable and strip newlines?
- How to print like printf in Python3?
- string to string array conversion in java
- What is the difference between \r\n, \r, and \n? [duplicate]
- Python convert tuple to string
- write() versus writelines() and concatenated strings
- Why is it string.join(list) instead of list.join(string)?
- Why is it string.join(list) instead of list.join(string)?
- Best way to strip punctuation from a string
- Split string with multiple delimiters in Python [duplicate]
- How to check if the string is empty?
- How to find all occurrences of a substring?
- What is the difference between a “line feed” and a “carriage return”?
- How to convert an int to string in C?
- How to check whether a str(variable) is empty or not?
- What does the ‘b’ character do in front of a string literal?
- How to add a string in a certain position?
- Check string “None” or “not” in Python 2.7
- Remove all special characters, punctuation and spaces from string
- This can be done without regex:
- How to replace all double quotes to single quotes using jquery?
- Pythonic way to create a long multi-line string
- Generate random string/characters in JavaScript
- “[ ]” vs. “[[ ]]” in Bash shell
- How to delete a character from a string using Python
- Python: Get the first character of the first string in a list?
- How to trim whitespace from a Bash variable?
- How to convert string to binary?
- Convert hex to binary
- Quoting backslashes in Python string literals
- Python string class like StringBuilder in C#?
- C – The %x format specifier
- Best way to replace multiple characters in a string?
- How do I remove a substring from the end of a string?
- Detect whether a Python string is a number or a letter
- Finding all possible permutations of a given string in python
- How do I append one string to another in Python?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- How to convert string to binary?
- Converting from a string to boolean in Python?
- Count the number of occurrences of a character in a string
- What is the difference between ‘ and ” in JavaScript?
- \n or \n in php echo not print [duplicate]
- bash : Bad Substitution
- Convert hex string to int in Python
- How can I check if character in a string is a letter? (Python)
- How can I find the first occurrence of a sub-string in a python string?
- Replacing a character from a certain index
- AttributeError: ‘list’ object has no attribute ‘lower’ gensim
- How to assign multiple lines string in Powershell Console
- Pandas error “Can only use .str accessor with string values”
- LC-3 STR with R1 as offset
- Convert a Unicode string to a string in Python (containing extra symbols)python string unicode type-conversion
- Create nice column output in python
- TypeError: decoding str is not supported
- AttributeError: ‘str’ object has no attribute ‘items’
- How to pad zeroes to a string?
- How does str(list) work?
- What is the difference between a string and a byte string?
- How can I copy a Python string?
- How to strip a specific word from a string?
- Checking if a string can be converted to float in Python
- Passing string to a function in C – with or without pointers?
- Python cant convert ‘list’ object to str error [closed]
- Difference between char* and char** (in C)
- Using strip() to clean up a string
- Extract filename and extension in Bash
- Meaning of #{ } in Ruby?
- Python code to remove HTML tags from a string
- Cannot concatenate ‘str’ and ‘float’ objects?
- How to repeat individual characters in strings in Python
- Taking a new line using printf in java? Is %n correct?
- When to use %r instead of %s in Python? [duplicate]
- How to count instances of character in SQL Column
- Python – difference between two strings