목록Programming (77)
IT is Smart
#coding=utf-8 #!/usr/bin/python from bs4 import BeautifulSoup html_doc = """ IT is SmartIT is Smart IT is Smart Once upon a time there were three little sisters; and their names were Elsie, Lacie and Tillie; and they lived at the bottom of a well. ... """ soup = BeautifulSoup(html_doc) # HTML 들여쓰기하여 출력하기 # ----------------------------------- # print(soup.prettify()) # # # IT is Smart # # # # #....
이번에는 딕셔너리라고 부르는 자료형에 대해 알아보겠습니다. 파이썬 IDLE를 실행한 후 편집기를 열고 코드를 따라해보세요. classmates = {'Tony': ' cool but smells', 'Emma': ' sits behind me', 'Lucy': ' asks too many questions'} for k, v in classmates.items(): print(k + v) 예제에서 보다시피 Dictionary 자료형은 { }로 구성요소들을 묶어줍니다. Set와 같은 모양입니다. Set와 다른 점은 구성요소가 KEY:VALUE가 한 쌍으로 되어 있다는 것입니다. 개별적으로 값을 찾는 방법은 classmates['Tony'] 라고 입력하면 ' cool but smells'가 리턴됩니다. --..
이번에는 파이썬의 자료형 중에서 Set에 대해 알아보겠습니다. 파이썬 IDLE를 실행한 후 편집기를 열고 코드를 따라해보세요. groceries = {'cereal', 'milk', 'starcrunch', 'beer', 'duck tape', 'lotion', 'beer'} print(groceries) if 'milk' in groceries: print("You already have milk hoss!") else: print("Oh yea, you need milk!") 이제까지 따라하기에서 본 자료형은 [ ]로 묶어서 사용하는 List였습니다. List는 구성요소를 0부터 시작하는 숫자로 찾도록 만들어진 자료형이었습니다. 이번에 보는 Set은 List와 다른 점은 { }로 묶어준다는 것이고, ..
이번에는 다중인자로 정의된 함수를 호출하는 방법에 대해 알아보겠습니다.파이썬 IDLE를 실행한 후 편집기를 열고 코드를 따라해보세요. def health_calculator(age, apples_ate, cigs_smoked): answer = (100-age) + (apples_ate*3.5) - (cigs_smoked*2) print(answer) buckys_data = [27, 20, 0] health_calculator(buckys_data[0], buckys_data[1], buckys_data[2]) health_calculator(*buckys_data) 인자의 기본값이 설정되어 있지 않으면 호출할 때도 모든 인자값을 넘겨줘야 합니다.이 때 함수 인자의 갯수와 배열의 길이가 같으면 * 마크..
이번에는 다수의 인자를 사용하는데 갯수를 고정하지 않고자 입력하는 대로 모두 처리하도록 하는 예제를 알아보겠습니다.파이썬 IDLE를 실행한 후 편집기를 열고 코드를 따라해보세요. def add_numbers(*args): total = 0 for a in args: total += a print(total) add_numbers() add_numbers(3) add_numbers(3, 32) add_numbers(3, 43, 5453, 354234, 463463) 이번 예제의 인자는 독특한 표식을 가지고 있습니다. * 마크가 붙어 있네요.* 마크의 의미는 인자의 갯수를 0개에서 입력하는대로 모두를 의미합니다. *은 자유입니다~ --------------------Source Code from thenew..
이번에는 함수의 인자를 사용하는 방법에 대해 알아보겠습니다.파이썬 IDLE를 실행한 후 편집기를 열고 코드를 따라해보세요. def dumb_sentence(name='Bucky', action='ate', item='tuna'): print(name, action, item) dumb_sentence() dumb_sentence("Sally", "farts", "gently") dumb_sentence(item='awesome') dume_sentence(item='awesome', action='is') 앞에서 봤듯이 함수의 인자는 사용하지 않을 수도 있지만 여러 개를 사용할 수도 있습니다.이번 예제에서는 3개의 인자를 사용했고, 각 인자는 모두 기본값이 설정되어 있습니다.따라서, 함수를 호출할때 인자..