How do you make line spacing in python?

I'm making a game in Python [text only] but it gets confusing when people play it because there is no space between the paragraphs, so it looks like this:

'You step outside and feel the wind on your face.'
'Which direction do you turn?'

But I would like it to look like this:

'You step outside and feel the breeze on your face'

'What do you do next'?

Here's my code:

print 'You step outside and feel the cool breeze on your face.'
what = raw_input ['What do you do next ']

Thanks!

Amber

487k81 gold badges616 silver badges545 bronze badges

asked Apr 10, 2012 at 0:25

Print a newline character.

print["\n"]

Or:

print["An angry-looking dwarf throws an axe at you.\nYou die.\n"]

answered Apr 10, 2012 at 0:26

Li-aung YipLi-aung Yip

12k5 gold badges31 silver badges49 bronze badges

You have a few solutions:

The simpler one would be to use a print statement between your lines, which, used alone, prints a line feed.

Alternatively, you could you end the string you're printing with a '\n' character, which will cause a line feed, or you could start your input with the same character.

answered Apr 10, 2012 at 0:28

Thomas OrozcoThomas Orozco

50.7k9 gold badges107 silver badges114 bronze badges

print['\v']

vertical tab for vertical space.

answered May 3, 2017 at 13:15

Mian Asbat AhmadMian Asbat Ahmad

3,02610 gold badges39 silver badges65 bronze badges

A paragraph has three spacing properties. It can have spacing that separates it from the prior paragraph, spacing that separates it from the following paragraph, and line spacing less than or greater than the default single line spacing.

Candidate protocol¶

Get and set space before/after:

>>> paragraph = TextFrame.add_paragraph[]
>>> paragraph.space_before
0
>>> paragraph.space_before = Pt[6]
>>> paragraph.space_before
76200
>>> paragraph.space_before.pt
6.0

An existing paragraph that somehow has space before or after set in terms of lines [] will return a value of Length[0] for that property.

Get and set line spacing:

>>> paragraph = TextFrame.add_paragraph[]
>>> paragraph.line_spacing
1.0
>>> isinstance[paragraph.line_spacing, float]
True
>>> paragraph.line_spacing = Pt[18]
>>> paragraph.line_spacing
228600
>>> isinstance[paragraph.line_spacing, Length]
True
>>> isinstance[paragraph.line_spacing, int]
True
>>> paragraph.line_spacing.pt
18.0

  • The default value for Paragraph.line_spacing is 1.0 [lines].

  • The units of the return value can be distinguished by its type. In practice, units can also be distinguished by magnitude. Lines are returned as a small-ish float. Point values are returned as a Length value.

    If type is the most convenient discriminator, the expression isinstance[line_spacing, float] will serve as an effective is_lines predicate.

    In practice, line values will rarely be greater than 3.0 and it would be hard to imagine a useful line spacing less than 1 pt [12700]. If magnitude is the most convenient discriminator, 256 can be assumed to be a safe threshold value.

MS API¶

LineRuleAfterDetermines whether line spacing after the last line in each paragraph is set to a specific number of points or lines. Read/write.LineRuleBeforeDetermines whether line spacing before the first line in each paragraph is set to a specific number of points or lines. Read/write.LineRuleWithinDetermines whether line spacing between base lines is set to a specific number of points or lines. Read/write.SpaceAfterReturns or sets the amount of space after the last line in each paragraph of the specified text, in points or lines. Read/write.SpaceBeforeReturns or sets the amount of space before the first line in each paragraph of the specified text, in points or lines. Read/write.SpaceWithinReturns or sets the amount of space between base lines in the specified text, in points or lines. Read/write.

PowerPoint behavior¶

  • The UI doesn’t appear to allow line spacing to be set in units of lines, although the XML and MS API allow it to be specified so.

XML specimens¶

Default paragraph spacing:


  
    Paragraph with default spacing
  

Spacing before = 6 pt:


  
    
      
    
  
  
    Paragraph spacing before = 6pt
  

Spacing after = 12 pt:


  
    
      
    
  
  
    Paragraph spacing after = 12pt
  

Line spacing = 24 pt:


  
    
      
    
  
  
    Paragraph line spacing = 24pt
  
  
  
    second line
  

Line spacing = 2 lines:


  
    
      
    
  
  
    Paragraph line spacing = 2 line
  
  
  
    second line
  

Schema excerpt¶


  
    
    
    
  



  
    
    
    
           
      
      
    
           
      
      
      
    
           
      
      
    
           
      
      
      
      
    
    
    
    
  
  
  
  
  
  
  
  
  
  
  
  



  
    
    
  



  



  



  
    
    
  



  
    
  



  



  
    
    
  

What does \t do in Python?

In Python strings, the backslash "\" is a special character, also called the "escape" character. It is used in representing certain whitespace characters: "\t" is a tab, "\n" is a newline, and "\r" is a carriage return. Conversely, prefixing a special character with "\" turns it into an ordinary character.

What is the space Command in Python?

Python isspace[] method is used to check space in the string. It returna true if there are only whitespace characters in the string. Otherwise it returns false. Space, newline, and tabs etc are known as whitespace characters and are defined in the Unicode character database as Other or Separator.

How do you put a space in a for loop in Python?

1 Answer.
use end="" and insert the whitespaces manually..
create a string and print after the loop: s = "" for n in range[n, n+7]: s+= str[n]+ " " s = s[:-1] #remove the ending whitespace print[s].
which I recommend: Using sys.stdout.write instead print: print only displays the message after a linebreak was printed..

How do I reduce line spacing in Python?

Python String strip[] function will remove leading and trailing whitespaces. If you want to remove only leading or trailing spaces, use lstrip[] or rstrip[] function instead.

Chủ Đề