문제 주소
https://school.programmers.co.kr/learn/courses/30/lessons/181951
문제
문제 설명
정수 a와 b가 주어집니다. 각 수를 입력받아 입출력 예와 같은 형식으로 출력하는 코드를 작성해 보세요.
제한사항
- 100,000 ≤ a, b ≤ 100,000
입출력 예
입력 #1
4 5
출력 #1
a = 4 b = 5
a, b = map(int, input().strip().split(' '))
print(a)
제출 코드
a, b = map(int, input().strip().split(' '))
print(f"a = {a}\nb = {b}")
a, b = map(int, input().strip().split(' '))
print("a =",a)
print("b =",b)
a, b = map(int, input().strip().split(' '))
print("a =", str(a))
print("b =", str(b))
공부한 것
⭐lambda
⭐How to merge string in Python?
We can perform string concatenation using following ways:
- Using + operator.
- Using join() method.
- Using % operator.
- Using format() function.
- Using f-string (Literal String Interpolation)
⭐Python String strip() Method
Remove spaces at the beginning and at the end of the string:
txt = " banana "x = txt.strip()print("of all fruits", x, "is my favorite")
banana
txt = ",,,,,rrttgg.....banana....rrr"
x = txt.strip(",.grt")
print(x)
banana
⭐Python map() Function
The map() function executes a specified function for each item in an iterable. The item is sent to the function as a parameter.
map(function, iterables)
Parameter Description
function | Required. The function to execute for each item |
iterable | Required. A sequence, collection or an iterator object. You can send as many iterables as you like, just make sure the function has one parameter for each iterable. |
Example 1
def myfunc(n):
return len(n)
x = map(myfunc, ('apple', 'banana', 'cherry'))
<map object at 0x056D44F0>
[5, 6, 6]
Example 2
def myfunc(a, b):
return a + b
x = map(myfunc, ('apple', 'banana', 'cherry'), ('orange', 'lemon', 'pineapple'))
<map object at 0x034244F0>
['appleorange', 'bananalemon', 'cherrypineapple']
⭐Python String split() Method
Split a string into a list where each word is a list item:
string.split(separator, maxsplit)
Parameter Description
separator | Optional. Specifies the separator to use when splitting the string. By default any whitespace is a separator |
maxsplit | Optional. Specifies how many splits o do. Default value is -1, which is "all occurrences" |
Example 1: Split the string, using comma, followed by a space, as a separator
txt = "welcome to the jungle"
x = txt.split()
print(x)
['welcome', 'to', 'the', 'jungle']
'Coding Test' 카테고리의 다른 글
[프로그래머스][Lv.1]바탕화면 정리 (0) | 2023.10.27 |
---|---|
[프로그래머스][Lv.1]공원 산책 (1) | 2023.10.26 |
[프로그래머스][Lv.1]추억 점수 (1) | 2023.10.23 |
[프로그래머스][Lv.1]달리기 경주 (0) | 2023.10.19 |
2-2. Add two numbers (0) | 2023.10.14 |