목록Programming/Python(파이썬) (44)
59doit

포맷팅 : % 문자를 사용해서 원하는 형식으로 포맷팅하는 방법이다. ' % + 자료형 종류 ' % 값의 형식으로 사용 a="i eat %d apples" % 3 print(a) # i eat 3 apples b="i eat %s apples" % "six" print(b) # i eat six apples number = 3 c = "i eat %d apples." % number print(c) # i eat 3 apples. number = 4 day = "three" d = "i ate %d apples. so i was sick for %s days." % (number, day) print(d) # i ate 4 apples. so i was sick for three days. 포맷팅활용 er..
문자열 위치 index str= "hi. nice to meet you mina and yuna." index = str.index("n") print(index) # 4 "n" 이라는 글자의 위치를 띄어쓰기 포함 하여 알려준다. 파이썬은 인덱싱이 0부터 시작이므로 n이 다섯번째에 있어서 결과값은 4가 나온다 str= "hi. nice to meet you mina and yuna." index2 =str.index("n",index+1) print(index2) # 23 str의 "n"을 찾는데 찾는값인 n의 index+1 은 n이 두번째로 있는 위치값을 찾아준다. find str= "hi. nice to meet you mina and yuna." print(str.find("hara")) # -1 ..
인덱싱 ; 문자열 자리 [ ](대괄호) 이용 ex) -1 : 뒤에서 첫번째, 0 : 앞에서 첫번째 a = "life is too short, you need python" b = a[-1] print(b) #n a = "life is too short, you need python" c = a[0] print(c) #L a[-1] > 문자열을 뒤에서부터 읽는다(-) a[0] > 문자열 맨앞자리는 1이 아닌 0부터 시작한다. 문자열 길이 len( ) / 문자열 곱하기 *x #문자열 길이 d = len(a) print(d) #34 # 문자열 곱하기 e = "python" f = e*2 print(f) #pythonpython 문자열 더해서 연산하기 : + # 문자열 더해서 연산하기 head = "안녕" ta..
따옴표 , \(역슬래시) : 파이썬 줄 바꿈을 시도 할 수 있다. \n : 한줄 아래로 줄 바꿈 할 문자 뒤에 \n하면된다. multiline = "life is too short\nyou need python" multiline=''' life is too short you need python ''' print(multiline) life is too short you need python \b : 앞글자삭제 print("나는는\b입니다") 나는입니다