n = int(input()) for i in range(1, n+1): print('*' * i) n에 int형을 입력 받고 1부터 시작해서 n + 1만큼 반복 (0부터 시작하기 때문에) *을 n번만큼 곱한 값을 출력 n+1만큼 반복
1. 숫자 판별 - isdecimal(): 문자열이 int형으로 변환 가능하면 true - isdigit(): 문자열이 숫자의 형태이면 true - isnumeric(): 숫자값 표현의 형태이면 true #int형 문자열 s = "12345" print(s.isdecimal())# True print(s.isdigit())# True print(s.isnumeric())# True #int형 + 문자 + 공백 s = "test 123" print(s.isdecimal())# False print(s.isdigit())# False print(s.isnumeric())# False 2. 문자 판별 - isalpha( ): 문자열이 알파벳으로만 이루어져있는지 확인하는 함수 숫자, 공백은 false s = "..
def solution(my_string): answer = list() for i in my_string: if (i.isdecimal()): answer.append(int(i)) return sorted(answer) string.isdecimal() 함수를 사용하여 숫자인지 판별 answer 리스트에 자료형을 int로 바꿔서 append sorted 함수를 사용하여 answer 정렬하여 리턴
type(value) -> 데이터 타입(자료형)을 확인하는 함수 print(type('a')) # str(value) -> 값을 문자열로 변환하는 함수 value = 100 print(type(value)) # print(type(str(value))) # value[index] / value[startIndex:endIndex:step] -> 문자열 인덱싱 / 슬라이싱 value = 'abcdefg' print(value[0], value[1], value[2], value[-2], value[-1]) # a b c f g print(value[1:5]) # bcde print(value[-3:-1]) # efg print(value[:]) # abcdefg print(value[3:]) # defg ..
[나의 풀이] def solution(cipher, code): answer = '' for i in range(code, len(cipher) + 1 ): if (i % code == 0): answer += cipher[i - 1] return answer 시작 숫자를 code로 지정하고 글자수 + 1 을 마지막 숫자로 정했다(0부터 시작이기 때문에) code의 배수값인지 확인을 위하여 i % code == 0 구문을 추가하였고 answer 에는 cipher[i-1] 값을 더해주었다 (마지막 숫자를 + 1 했기 때문에) [개쩌는 풀이] def solution(cipher, code): answer = cipher[code-1::code] return answer 문자열 슬라이싱을 활용하여 string..
def solution(my_string): return my_string.swapcase() 텍스트 관련 함수를 찾다가 swapcase()를 발견했다! 대문자 -> 소문자, 소문자 -> 대문자 로 변환해주는 함수