파이썬 초격차 공부 - 2

컴순이·2022년 12월 23일
0

문자열

.upper() .lower() .replace(str1, str2) .find(str) .count(str)

.split() .split(,)
''.join([str1, str2]) : str1 str2
','.join([str1, str2]) : str1, str2

공백 삭제 lstrip rstrip strip

문자열 포매팅

format 메서드

'Hello {0}'.format('world')
>> 'Hello world'

'Hello {0} {1} {2}'.format('a', 'b', 'c')
= 'Hello {} {} {}'.format('a', 'b', 'c')
>> 'Hello a b c'

fstring f'Today is {month} {date}'

할당과 복사

id(변수) : 변수의 주소값

# 복사
x = [1, 2, 3, 4, 5]
y = x.copy()

# 다차원 복사
import copy
x = [[1, 2], [3, 4, 5]]
y = copy.deepcopy(x)

함수

가변 매개 변수: 개수가 정해지지 않는 매개 변수

위치 가변 매개함수

튜플형

def print_fruits(*args):
/ print_fruits('apple', 'orange', 'mango')

def post_info(*tags, title, num):
/ post_info('#파이썬', '#함수', title = 파이썬 초격차 공부, num = 2)

키워드 가변 매개함수

딕셔너리형

def comment_info(**kwargs):
	for key, value in kwargs.items():
    	print(f'{key}: {value}')
/ comment_info('컴순이', '12/23')

변수 중 가장 마지막에 사용해야 함

람다 함수

def minus_one(a):
	 return a - 1
/ minus_one(10)

(lambda a: a - 1)(10)

minus_one = lambda a: a - 1
/ minus_one(10)

lambda b: True if b > 0 else False

map 함수

items = list(map(lambda x: x.strip(),items)

filter 함수

filter(함수, 리스트) : 리스트 중 함수가 True인 것들만 return

profile
음음

0개의 댓글