Python Forum
Format text and variables - more lines
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Format text and variables - more lines
#1
Hello,

is there any way how to put such a code into more lines?

print(f'string{variable}string...')
Reply
#2
two examples (I would go for the first one):
print(f'string\n{variable}\n\nstring...')
print(f'''string
{variable}


string...''')
Is that what you were looking for?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thanks, what I want is to make my code more readable, so I went for the second one.

And one additional question - is there any way how to make output of this print without these quotation marks "? Actually I want to write this into a file and there would be nice to have just a clear text.
Reply
#4
quotation marks denote it's a string. when writing to text file properly they will not be present (at least in most of the cases - there are certain cases when you DO want to quote what you write to the file). show your code in python tags, so we can help - you are doing something wrong. Is the reason to ask how to put them on different lines is to have them on different lines in the file?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Editing text between two string from different lines Paqqno 1 1,311 Apr-06-2022, 10:34 PM
Last Post: BashBedlam
  Extracting Specific Lines from text file based on content. jokerfmj 8 2,953 Mar-28-2022, 03:38 PM
Last Post: snippsat
  raspberry use scrolling text two lines together fishbone 0 1,450 Sep-06-2021, 03:24 AM
Last Post: fishbone
  More elegant way to remove time from text lines. Pedroski55 6 3,926 Apr-25-2021, 03:18 PM
Last Post: perfringo
  how to connect mysql from txt 1 line goes good but not all lines in text kingceasarr 4 2,854 Mar-24-2021, 05:45 AM
Last Post: buran
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 5,825 Aug-10-2020, 11:01 PM
Last Post: medatib531
  Read Multiples Text Files get specific lines based criteria zinho 5 3,117 May-19-2020, 12:30 PM
Last Post: zinho
  How to detect the text above lines using OpenCV in Python pframe 0 2,513 Apr-14-2020, 09:53 AM
Last Post: pframe
  Can't seem to figure out how to delete several lines from a text file Cosmosso 9 4,120 Dec-10-2019, 11:09 PM
Last Post: Cosmosso
  variables from a text file vlk 2 2,231 Sep-22-2019, 06:44 PM
Last Post: vlk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020