Python 배우기50 in_operator.py ice_cream = "ice cream" print("cream" in ice_cream) # print boolean result directly contains = "ice cream" print("ice" in contains) 산출물 (output) TrueTrue * string에 특정 letter 또는 substring이 포함되어 있는지 여부를 체크하려면, 키워드 "in"을 사용합니다. 2016. 3. 6. slicing.py monty_python = "Monty Python" monty = monty_python[:5] # one or both index could be dropped. monty_python[:5] is equal to monty_python[0:5] print(monty) python = monty_python[6:12] print(python) 산출물 (Output) Monty Python * Slicing을 이용하여 string으로부터 복수의 글자들(substring)을 얻습니다. 슬라이싱의 신택스는 indexing의 신택스와 비슷하지만, 1개의 인텍스 대신 colon으로 구분되는 2개의 indices (숫자들)를 사용합니다(예, str[ind1:ind2]). 2016. 3. 6. negative_indexing.py long_string = "This is a very long string!" exclamation = long_string[-1] print(exclamation) 산출물 (Output)!* string의 끝으로부터 '뒷쪽으로' 글자를 계산하기 위하여 인덱싱 연산자에서 부의 숫자를 사용할 수 있습니다. 2016. 3. 6. string_indexing.py python = "Python" print("h " + python[3]) # Note: string indexing starts with 0 p_letter = python[0] print(p_letter) 산출물 (Output)h hP * 글자의 위치를 안다면 문자열의 글자에 접근할 수 있습니다. 예를 들어, str[index]는 문자열 'str" 안의 ‘index’ 위치에 있는 글자를 yield 합니다. string index는 항상 0에서 시작된다는 것을 알아야 합니다. 2016. 3. 6. string_multiplication.py hello = "hello" ten_of_hellos = hello * 10 print(ten_of_hellos) 산출물 (Output)hellohellohellohellohellohellohellohellohellohello * Python은 string-by-number multiplication를 지원합니다(but not the other way around!). 2016. 3. 6. concatenation.py hello = "Hello" world = 'World' hello_world = hello + " "+ world print(hello_world) # Note: you should print "Hello World" 산출물 (Output)Hello World * + symbol를 사용하여 2개의 문자열을 결합하는 것을 concatenation라고 합니다. 2016. 3. 6. 이전 1 2 3 4 5 6 7 8 9 다음