About 469,000 results
Open links in new tab
  1. How can I print variable and string on same line in Python?

    File "print_strings_on_same_line.py", line 16 print fiveYears ^ SyntaxError: Missing parentheses in call to 'print' Then, I modified the last line where it prints the number of births as follows:

  2. python - How can I print multiple things (fixed text and/or variable ...

    OP of this question originally clearly had a string-formatting approach in mind, which would make the question a) a duplicate and b) caused by a typo (clearly the intent is to use %-style formatting, but the actual % operator is not used as required).

  3. Print variable and a string in python - Stack Overflow

    If the Python version you installed is 3.6.1, you can print strings and a variable through a single line of code. For example the first string is "I have", the second string is "US Dollars" and the variable `card.pricè is equal to 300, we can write the code this …

  4. python - How can I print multiple things on the same line, one at a ...

    Apr 8, 2011 · Python 3 Solution. The print() function accepts an end parameter which defaults to \n (new line). Setting it to an empty string prevents it from issuing a new line at the end of the line.

  5. python - Print Combining Strings and Numbers - Stack Overflow

    Aug 18, 2012 · To print strings and numbers in Python, is there any other way than doing something like: first = 10 second = 20 print "First number is %(first)d and second number is %(second)d" % {"first": first, "

  6. python - Print to the same line and not a new line? - Stack Overflow

    In python 3, this solution is pretty elegant and I believe does exactly what the author is looking for, it updates a single statement on the same line. Note, you may have to do something special if the line shrinks instead of grows (like perhaps make the string a …

  7. new line with variable in python - Stack Overflow

    for x in a: print(x) or abuse star unpacking to do it as a single statement, using sep to split outputs to different lines: print(*a, sep="\n") If you want a blank line between outputs, not just a line break, add end="\n\n" to the first two, or change sep to sep="\n\n" for the final option.

  8. How do I write output in same place on the console?

    when sep is the separator of the arguments from args*, end is how to end the printed line ('\n\ means a new line) file is to where print the output (stdout is the consul) and flush is if to clean the buffer. Usage Example import sys a = 'A' b = 0 c = [1, 2, 3] print(a, b, c, 4, sep=' * ', end='\n' + ('-' * 21), file=sys.stdout, flush=True) Output

  9. Assign and print at the same time in Python - Stack Overflow

    Dec 27, 2018 · Technically you can "print" and assign on the same line by using sys. See the following: >>> import sys >>> a = sys.stdout.write("hello") hello >>> print(a) 5 As you can see, you "print" - by writing to standard out which is essentially the the same as print() - the string and assign the length of the string to the variable - not the string itself.

  10. How do I create a multiline Python string with inline variables?

    Apr 12, 2012 · You can use Python 3.6's f-strings for variables inside multi-line or lengthy single-line strings. You can manually specify newline characters using \n . Variables in a multi-line string

Refresh