python-24: URL Formatting
- startswith는 문자열이 특정문자로 시작하는지 여부를 알려준다. true나 false 를 반환
websites = [
'https://google.com',
'naver.com',
'https://daum.net',
'kakao.com']
for website in websites:
if website.startswith('https://'):
print(website)
else:
print('https://' + website)
websites = [
'https://google.com',
'naver.com',
'https://daum.net',
'kakao.com']
for website in websites:
if not website.startswith('https://'):
print(f'https://{website}')
else:
print(website)
for website in websites:
if not website.startswith('https://'):
website = f'https://{website}'
print(website)
print(websites)
- for문 안에서 website를 변경하였으나 websites 리스트 원본은 변경되지 않는다. website가 지역변수이기 때문이다.
- String안에 변수를 넣는 방법 : f””
댓글남기기