HackerRank-Python

Prepare > Python > Strings > What's Your Name?

stem_sw 2023. 6. 30. 21:34
 

What's Your Name? | HackerRank

Python string practice: Print your name in the console.

www.hackerrank.com

 

문제


You are given the firstname and lastname of a person on two different lines. Complete the print_full_name function in the editor below.

 

=> 이름 완성해서

Hello firstname lastname! You just delved into python.

위 형식으로 출력해라

 

 

 

 

코드


def print_full_name(first, last):
    print(
        f"Hello {first} {last}! You just delved into python."
    )

if __name__ == '__main__':

 

 

노트


문자열 포맷팅 %

def print_full_name(first, last):
    print(
        "Hello %s %s! You just delved into python."%(first, last)
    )

if __name__ == '__main__':

 

 

문자열에 변수 넣기

"""
print(
"~~~%s ~~~~ %d ~~~ %f"%([문자열], [정수], [소수])
)
"""

print(
    "Hello %s JaeJun, you must be %d years old"%("Jo", 21)
)
Hello Jo JaeJun, you must be 21 years old

 

# 직접 대입하기
s1 = 'name : {0}'.format('BlockDMask')
print(s1)
 
 
# 변수로 대입 하기
age = 55
s2 = 'age : {0}'.format(age)
print(s2)


# 이름으로 대입하기
s3 = 'number : {num}, gender : {gen}'.format(num=1234, gen='남')
print(s3)
name : BlockDMask
age : 55
number : 1234, gender : 남

 

 

 

 

참조


 

[python] 파이썬 f-string (문자열 포매팅 방법 3)

안녕하세요. BlockDMask 입니다. 오늘은 파이썬 문자열 포매팅 방법 % 서식문자, str.format, f-string 이 세개 중 마지막인 f-string에 대해서 알아보려고 합니다.% 서식문자 [바로가기] str.format [바로가기]

blockdmask.tistory.com

 

[python] 파이썬 % 서식 기호 (문자열 포매팅 방법 2)

안녕하세요 BlockDMask 입니다. 파이썬 문자열 포매팅 방법들 % 서식기호, format함수, f-string중에서 % 서식 기호에 대해서 알아보려고 합니다. format 함수에 대해서 알고 싶다면 [바로가기] 1. % 포매팅

blockdmask.tistory.com