라벨이 string인 게시물 표시

파이썬[Python]: string - Template 클래스

string 모듈 - Template 클래스(class) /// 설명 문자열을 치환할 수 있는 객체입니다. $를 기반으로 합니다.($$=escape, $_, $alphabet, ${ }) ※ 형식 class string.Template(template) reference https://docs.python.org/release/3.10.0/library/string.html /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 from  string  import   *   test_str  =   '$first is a first name and $last is a last name'   s  =  Template(test_str) print (s.substitute(first = 'alan' , last = 'Turing' )) # alan is a first name and Turing is a last name   test_str  =   '${first} is a first name and ${last} is a last name'   s  =  Template(test_str) print (s.substitute(first = 'alan' , last = 'Turing' )) # alan is a first name and Turing is a last name   test_str  =   '$_first is a first name and $_last is a last name'   s  =  Template(test_str) print (s.substitute(_first = 'alan' , _last = 'Turing' )) # alan is a first name and Turing is a last name   Colored by Col

파이썬[Python]: string - Formatter 클래스

string 모듈 - Formatter 클래스(class) /// 설명 사용자가 일정한 형식을 가지고 있는 문자열을 생성할 수 있도록 합니다. ※ 형식 class string.Formatter reference https://docs.python.org/release/3.10.0/library/string.html /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 from  string  import   *   a  =  Formatter()   print (a. format ( 'one: {}, two: {}, three {}' ,  1 ,  2 ,  3 ))   # one: 1, two: 2, three 3 print (a. format ( 'one: {1}, two: {0}, three {2}' ,  '1' ,  '2' ,  '3' ))   # one: 2, two: 1, three 3   test_str  =   'name: {first}, {last}'   print (a. format ( 'name: {first}, {last}' , first = 'alan' , last = 'Turing' ))   # name: alan, Turing   test_dict  =  { 'first' :  'alan' ,  'last' :  'Turing' } print (a. format ( 'name: {first}, {last}' ,  * * test_dict))   # name: alan, Turing   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –