문자열 6

[python]문자열 reverse, reversed

※ 리스트.reverse() 해당 리스트 역순으로 수정해줄 뿐 None return => list에서만 제공되는 함수!!! a_li = ['a', 'b', 'c', 'd'] b_li = a_li.reverse() print(b_li) # none print(a_li) # ['d', 'c', 'b', 'a'] ※ reversed(리스트/튜플/문자열) 역순으로 된 reversed 객체 return! list(reversed(a_li)) # ['d', 'c', 'b', 'a'] or ''.join(reversed(a_li)) # 'dcba' 처럼 활용가능! https://itholic.github.io/python-reverse-reversed/ ※ 문자열 뒤집기(역순 출력) 문자열은 슬라이싱(인덱스)으로 추..

Coding/Python 2024.04.19

[python]문자열 인덱싱

※ 콜론[:]을 활용한 문자열 인덱싱text = 'abcdef'text[0] = 'a'text[0:2] = 'ab'text[-2:0] = 'ef'text[:-3] = 'abc'text[::2] = 'ace'  # 0번째 문자부터 끝까지 2개씩 건너뛰기# 프로그래머스 lv0 코드 처리하기def solution(code): mode = False # 0 ret = "" for i in range(len(code)): if code[i] == "1": # 숫자 1이 아닌 문자열 1이라는 것 놓치지 않기! mode = not mode elif (mode == False and i%2 == 0) or (mode == True and i%2 == ..

Coding/Python 2024.04.17

[python]문자열 format, raw string

f'문자열 {변수}' # 백준 10926 print(input() + "??!") # f-string a = input() print(f"{a}??!") #프로그래머스 a, b = map(int, input().strip().split(' ')) print(f"a = {a}\nb = {b}") print(f"{a} + {b} = {a+b}") print("{} + {} = {}".format(a, b, a+b)) # 더 크게 합치기 def solution(a, b): # return max(int(str(a) + str(b)), int(str(b) + str(a))) return max(int(f"{a}{b}"), int(f"{b}{a}")) "%d %s" % (값, 값) # 백준 2525 h, m = ..

Coding/Python 2024.03.14