본문 바로가기
뇌새김질

[Python] String 포맷 & prefix (f, b, u, r)

by 파란소스 2021. 7. 15.

1. f prefix : format

  _name = jack

  _msg = f'Hi {_name}'

  print(_msg) => Hi Jack

 

2. b prefix : bytes

  _str = 'this is string'

  _bytestr = b'this is byte string'

  print(_str) => this is string

  print(_bytestr) => b'this is byte string'

 

3. u prefix : unicode

  python 3 defaut encoding is unicode. don't need to use 'u'

 

4. r prefix : raw

  ignore escape character

  print('It is raw prefix.\nIs it right?')

   => It is raw prefix.

        Is it right?

  print(r'It is raw prefix.\nWrong!')

   => It is raw prefix.\nWrong

 

5. 문자열 포맷(format)