dic = {1:"홍길동", 22:"홍진호"} print(dic[1]) # 홍길동 print(dic[22]) # 홍진호 print(dic.get(1)) # 홍길동 print(dic.get(2), "비어있음") # None 비어있음 print(1 in dic) # True print(2 in dic) # False dic[1] = "이길동" print(dic[1]) # 이길동 dic[2] = "이순신" print(dic[2]) # 이순신 del dic[2] print(dic) # {1: '이길동', 22: '홍진호'} print(dic.keys()) # dict_keys([1, 22]) print(dic.values()) # dict_values(['이길동', '홍진호']) print(dic.items()..
fruit = ["사과", "오렌지", "바나나"] print(fruit) # ['사과', '오렌지', '바나나'] print(fruit.index("오렌지")) # 1 fruit.append("멜론") print(fruit) # ['사과', '오렌지', '바나나', '멜론'] fruit.insert(1, "키위") print(fruit) # ['사과', '키위', '오렌지', '바나나', '멜론'] fruit.append("사과") print(fruit) # ['사과', '키위', '오렌지', '바나나', '멜론', '사과'] print(fruit.count("사과")) # 2 fruit.sort() print(fruit) # ['멜론', '바나나', '사과', '사과', '오렌지', '키위'] fru..
\n - 줄바꿈 \" - " 출력 \' - ' 출력 \\ - \ 출력 \r - 커서를 맨 앞으로 이동 \b - 한 글자 삭제 \t - 탭
1. +를 이용한 방식 print("hello, " + "world!") # hello, world! 2. , 를 이용한 방식 print("hello, ", "world!") # hello, world! 3. %d, %c, %s ... 를 이용한 방식 print("hello %s" % "world") # hello world print("hello %s %s" % ("python", "world")) # hello python world 4. {}, format을 이용한 방식 print("hello {}".format("world")) # hello world print("hello {}{}".format("python", "world")) # hello python world print("hello {..
string = "Hello, World" print(string.lower()) #hello, world print(string.upper()) #HELLO, WORLD print(string[0].isupper()) # True print(len(string)) # 12 print(string.replace("Hello", "Bye")) # Bye, World index = string.index("o") print(index) # 4 index = string.index("o", index + 1) print(index) # 8 print(string.find("Bye")) # -1 print(string.count("o")) # 2 x.lower() - 문자열 x를 소문자로 변경 x.upper()..
string = "hello, world" print(string[0]) # h print(string[2:4]) # ll print(string[1:10]) # ello, wor print(string[:10]) # hello, wor print(string[1:]) # ello, world\ print(string[-5:]) # world 문자열로 입력된 값은 배열의 인덱스를 통해 해당 값을 불러올 수 있습니다. [x:y]로 접근하여 x부터 y까지 의값을 불러올 수 있으며, x나 y를 생략하면 x는 처음부터, y는 끝까지라는 의미를 가집니다.