바다는 비에 젖지 않는다

[Python] f-string with for loops 본문

IT Technical Note/Python

[Python] f-string with for loops

Soroya 2022. 9. 5. 20:31
728x90
websites = (
  "google.com",
  "airbnb.com",
  "https://twitter.com",
  "facebook.com",
  "https://tiktok.com",
)

for website in websites:
  if not website.startswith("https://"):
    website = f"https://{website}"
  print(website)

f-string은 Python3.6 에서부터 문자열을 더 쉽게 포맷팅하기 위해 만들어진 기능이라고 한다.

f"" 따옴표 안에 수정하고싶은 문자열을 넣어 수정해줄수 있고 {}를 이용해 기존에 존재하는 변수를 수정해줄수 도 있다.

 

수정된 websites tuple

 

굉장히 편리한 기능인것 같다.

확실히 python이 재미있고 편한 기능들이 많은것 같다.

728x90