pyvo-lt.pdf

7b2e4bf7ecca28e530e1c421f0676c0b?s=47 Honza Javorek
June 16, 2018
26

 pyvo-lt.pdf

7b2e4bf7ecca28e530e1c421f0676c0b?s=128

Honza Javorek

June 16, 2018
Tweet

Transcript

  1. Format

  2. name = input('Name: ')

  3. print('Hello ', end='') print(name, end='') print('!')

  4. print('Hello ' + name + '!')

  5. year = 2018 print('Happy new year ' + year +

    '!')
  6. TypeError: must be str, not int

  7. 'Happy new year %d!' % (year,)

  8. 'Your name is %s' % (name,) 'Hello %s and %s!'

    % (n1, n2) 'Happy new year %d!' % (year,)
  9. 'Happy new year %s' % (year,) 'pi = %d' %

    (3.14,)
  10. '%10s' % (3.14,) ' 3.14'

  11. C sprintf()

  12. print('Hello {0}!'.format(name))

  13. print(('Hello {0}! {0} is a nice' 'name.').format(name))

  14. print('Hello {} and {}!'.format(n1, n2))

  15. '{:>10}'.format(3.14) ' 3.14'

  16. name = { 'first': 'Honza', 'last': 'Javorek', } print('Hi {first}

    {last}!'.format(**name))
  17. print('Hi {first} {last}!'.format( first='Honza', last='Javorek', ))

  18. a = { 'street': 'Ostrovského', 'no': '38a', } print('{a[street]} {a[no]}'.format(a=a))

  19. c = [50.0678996, 14.3953814] print('GPS: {c[0]};{c[1]}'.format(c=c))

  20. from datetime import datetime d = datetime(2018, 6, 20, 19,

    0) print('{:%Y-%m-%d %H:%M}'.format(d))
  21. pyformat.info

  22. address = { 'street': 'Ostrovského', 'no': '38a', } coords =

    [50.0678996, 14.3953814] text = ('The address is: ' '{address[street]}{address[no]}' '\n' 'GPS: {coords[0]};' '{coords[1]}').format(address=address, coords=coords) print(text)
  23. text = ( 'The address is: ' '{address[street]}{address[no]}' '\n' 'GPS:

    {coords[0]};' '{coords[1]}' ).format( address=address, coords=coords ) print(text)
  24. print(( 'The address is: ' '{address[street]}{address[no]}\n' 'GPS: {coords[0]};{coords[1]}').format( address=address, coords=coords

    )))))))!:!)!*&^%^FUUUUUUUUUU .format( address=address, coords=coords )
  25. name = 'Honza' year = 2018 print(f'Hello {name}!') print(f'Happy {year}!')

  26. name = 'Honza' year = 2018 print(f'Hello {name.upper()}!') print(f'Next: {year

    + 1}')
  27. theend = dict( cs='konec', en='the end', fr='el fin', ) print(f"{theend['cs'].upper()}")