끄적끄적 코딩
[파이썬] 튜플
Python 2020. 9. 10. 08:26

JS = ("J3SUNG", "10", "codding") 괄호로 값들을 선언해서 사용하며 리스트와 동일하게 JS[0], JS[1], JS[2]로 접근이 가능합니다 해당 값들은 고정값이므로 변경이 불가능 함

[파이썬] 딕셔너리
Python 2020. 9. 10. 08:22

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()..

[파이썬] 리스트
Python 2020. 9. 10. 08:00

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..

[파이썬] 탈출문자
Python 2020. 9. 10. 07:37

\n - 줄바꿈 \" - " 출력 \' - ' 출력 \\ - \ 출력 \r - 커서를 맨 앞으로 이동 \b - 한 글자 삭제 \t - 탭

[파이썬] print 출력 방식
Python 2020. 9. 10. 07:29

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 {..

[파이썬] 문자열 처리 함수
Python 2020. 9. 10. 07:05

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()..

[파이썬] 슬라이싱
Python 2020. 9. 10. 04:11

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는 끝까지라는 의미를 가집니다.

[파이썬] 문자열
Python 2020. 9. 10. 04:05

string1 = 'hello' string2 = "world" string3 = """ hello world """ 문자열을 입력할 때 ' '와 " "로 입력할 수 있습니다. 줄바꿈이 포함된 문자열을 입력하기 위해서 """ (큰따옴표 3개)를 시작부분과 끝부분에 입력한 후에 사이에 문자를 입력하면 줄바꿈이 포함된 문자를 입력할 수 있습니다. print(string3) 출력결과 hello world

검색 태그