Skip to content
Snippets Groups Projects
Select Git revision
  • 1267ecb7fdaee73c8f66d15a29c1016b646caafe
  • master default protected
2 results

test_heap.py

Blame
  • Forked from Vuillemot Romain / INF-TC1
    Source project has a limited visibility.
    util-format.py 1.88 KiB
    from math import pi
    
    s = "Python"
    s.center(10)         # centrer sur 10 positions
    print(s)
    # Donne -->'  Python  '
    
    s.center(10,"*")       # centrer sur 10 positions en complétant par des '*'
    # Donne -->'**Python**'
    print(s)
    
    s = "Training"
    s.ljust(12)           # justifier à gauche sur 12 positions} 
    # Donne -->'Training    '
    print(s)
    
    s.ljust(12,":")
    # Donne -->'Training::::'
    
    s = "Programming"
    s.rjust(15)
    # Donne -->'    Programming'
    s.rjust(15, "~")
    # Donne -->'~~~~Programming'
    
    account_number = "43447879"
    account_number.zfill(12)
    # Donne -->'000043447879'
    
    # Même chose avec rjust : 
    account_number.rjust(12,"0")
    # Donne -->'000043447879'
    
    s = 'Hello, world.'
    str(s)
    # Donne -->'Hello, world.'
    
    repr(s)
    # Donne --> "'Hello, world.'"
    str(1/7)
    # Donne --> '0.14285714285714285'
    
    r=2
    print("La surface pour un rayon {rayon:3d} sera {surface:8.3f}".format(surface=r*r*pi, rayon=r))
    # Donne -->  'La surface pour un rayon   2 sera   12.566'
    
    x = 10 * 3.25
    y = 200 * 200
    s = 'The value of x is ' + repr(x) + ', and y is ' + repr(y) + '...'
    print(s)
    # Donne --> The value of x is 32.5, and y is 40000...
    
    # Le repr() d'un string ajoute des quotes et backslashes:
    hello = 'hello, world\n'
    str(hello)
    # Donne --> 'hello world\n'
    repr(hello)
    # Donne --> 'hello, world\\n' %*  {\color{magenta}  noter le double slash}    *)
    
    # L'argument d'appel de repr() peut être n'importe quel objet  Python :
    repr((x, y, ('spam', 'eggs')))
    # Donne -->"(32.5, 40000, ('spam', 'eggs'))"
    
    for x in range(1, 11):
        print(repr(x).rjust(2), repr(x*x).rjust(3), repr(x*x*x).rjust(4))
    # Donne -->
    #  1   1    1
    #  2   4    8 
    #  3   9   27
    #  4  16   64
    #  5  25  125
    #  6  36  216
    #  7  49  343
    #  8  64  512
    #  9  81  729
    # 10 100 1000
    
    for x in range(1, 6):
        print(repr(x).rjust(2), end='#'*x+'\n')    # on ajoute x fois \# + \textbackslash n à la fin de chaque ligne}  *)
    
    # Donne -->
    #  1#
    #  2##
    #  3###
    #  4####
    #  5##### 
    #