# String
str1 = "I am girl."
str2 = "Hi"
str3 = ""
str4 = str("")
print(len(str1), len(str2), len(str3), len(str4))
escape_str1 = 'I love "fruits"'
print(escape_str1)
escape_str2 = "Tab\tTab\t"
print(escape_str2)
# Raw String
raw_s1 = r"C:\Programs\Test\Bin"
print(raw_s1)
raw_s2 = r"\\a\\a"
print(raw_s2)
rae_s3 = r"print\nprint"
# Multi line
- 변수 선언 뒤 \ 있으면 다음줄에 이어지는 것을 의미. 줄 바꿈하는데 \안쓰면 에러남.
multi = """
문자열
멀티라인
테스트
"""
print(multi)
# String operation
str_o1 = "*"
str_o2 = "abc"
str_o3 = "def"
str_o4 = "BTS"
print(str_o1 * 10)
print(str_o2 + str_o3)
print(str_o1 * 3)
print("a" in str_o4)
print("f" in str_o4)
print("z" not in str_o4)
# String 형 변환
print(str(777) + "a")
print(str(10.4))
# String 함수
a = "Hi"
b = "hello world"
print(a.islower())
print(a.endswith("s"))
print(b.capitalize())
print(b.replace("hello", "bye"))
print(list(reversed(b)))
참고 : https://www.w3schools.com/python/python_ref_string.asp
- Sring 한번 할당되면 반환 불가능
# Slicing
c = "Pineapple"
d = "orange"
print(c[0:3])
print(c[0:4])
print(c[0:7])
print(c[0 : len(c)])
print(c[:4])
print(c[:])
print(d[0:4:2])
print(d[1:-2])
print(d[::-1])