Python Code Examples

Growing collection of Python programming examples

Category: print operation

  • Output

    ---------------apple----------
    ----------applejuice----------
    --------------banana----------

    Python Code

    def header_with_text(txt):
       print('-'*(30-len(txt))+txt+'-'*10)
       return None
    
    #Execute 
    header_with_text('apple')
    header_with_text('applejuice')
    header_with_text('banana')

    Description

    # the print output consist of three parts, 
    # first part (just some '-') and second part (text) together share "always" the same length (20 chars), in this same length area, text is right aligned,
    # third part (just 10 times '-')
    # all parts together is fixed length 30

    +