파이썬기초34 : URL 만들기 예제 01
작성자 정보
- 관리자 작성
- 작성일
컨텐츠 정보
- 2,881 조회
- 0 추천
- 목록
본문
#function.py
def Times(a=10, b=20):
return a*b
print(Times())
print(Times(5))
print(Times(5,6))
#키워드 인자
def connectURI(server,port):
str = "http://" + server + ":" + port
return str
print(connectURI("credu.com", "80"))
print(connectURI(port="8080", server="test.com"))
#가변인자(인자의 갯수가 가변적인 경우)
def union(*ar):
res = []
for item in ar:
for x in item:
if not x in res:
res.append(x)
return res
print(union("HAM","SPAM"))
print(union("HAM","SPAM","GIRL"))
print(union("HAM","SPAM","GIRL","GENERATION"))
#정의되지 않은 인자(**)
def userURIBuilder(server, port, **user):
str = "http://"+ server + ":" + port + "/?"
for key in user.keys():
str += key +"=" + user[key]+ "&"
return str
print(userURIBuilder("test.com", "80", id="kim", password="1234"))
print(userURIBuilder("test.com", "80", id="kim", password="1234", age="30"))
관련자료
-
이전
-
다음