반응형

Python 21

[Python]온라인에 있는 라이브러리 사용해서 url 가져오기

indeed 웹사이트의 html정보 가져오기 github에 있는 request코드 복사하기 repl.it에서 패키지에 requests라이브러리 검색해서 설치 import requests indeed_result = requests.get("https://www.indeed.com/jobs?q=python&limit=50&radius=25&start=950") print(indeed_result.text) #html코드 가져오기 3. 코드 복붙해서 html정보를 전부 불러옴 페이지 정보(페이지 숫자들)를 불러오기 위해서 screen scrapping라이브버리인 beautifulsoup을 사용 beautifulsoup : html에서 정보를 추출하기에 유용한 라이브러리 4. repl.it 패키지에서 beau..

Python 2021.11.20

[Python]모듈(Module)

math : 값을 올림해서 반환 import math #import를 사용해서 module가져오기 print(math.ceil(1.2)) 2 fabs :절대값 반환 import math print(math.fabs(-1.2)) 1.2 math를 import하면 기능을 다 가져오게 됨, math에 있는 기능 전부 import할 필요는 x //특정 함수만 가져오려면 from.. import사용 from math import ceil, fsum print(ceil(1.2)) print(fsum([1,2,3,4,5,6,7])) 2 28.0 항상 사용할 것만 import 한다, module전부를 가져올 필요x from math import fsum as fancy_sum #as를 사용해서 이름 지정 가능 prin..

Python 2021.11.20

[Python]for in 반복문

days = ("Mon","Tue","Wed", "Thur","Fri") //튜플 생성 for day in days: //for..in문 생성 print(day) Mon Tue Wed Thur Fri days = ("Mon","Tue","Wed", "Thur","Fri") for day in [1,2,3,4,5]: print(day) 1 2 3 4 5 day 변수는 선언되는 것이 아니라 작업이 시작되면 생김 즉 for문이 실행될때 만들어진다 for..in문에서 변수(day)는 작업되는 배열의 item을 가리킨다 // for loop를 멈추는법 days = ("Mon","Tue","Wed", "Thur","Fri") for day in days: if day is "Wed": break else: prin..

Python 2021.11.19

[Python]if...else, elif..or/and

// b의 타입이 number일때 a+b를 return하고, b가 number가 아니라면 None을 return한다 // b의 타입이 int이거나 float이라면 a+b를 return하고, 위의 조건이 아니라면 None을 return def plus(a,b): if type(b) is int or type(b) is float: return a + b else: return None print(plus(12, 1.2)) 13.2 def age_check(age): print(f"you are {age}") //string안에 변수를 출력하는 문법 if age < 18: print("you cant drink") elif age == 18: print("you are new to this!") elif a..

Python 2021.11.19

[Python]Keyworded Arguments

// String formatting def say_hello(name, age): return f"Hello {name} you are {age} years old" hello = say_hello("Nico","12") print(hello) Hello Nico you are 12 years old string앞에 f(format)를 붙이고 변수의 이름을 { }로 감싸주면 {name}, {age}는 실제 변수의 이름을 나타낸다 = "Hello" + name + "you are" + age + "years old" // argument가 두개인 경우 인자의 순서를 바꿀때 keyword argument사용 def say_hello(name, age): return f"Hello {name} you are..

Python 2021.11.19

[Python]return

def p_plus(a, b): print (a + b) def r_plus(a, b): return a + b p_result = p_plus(2,3) r_result = r_plus(2,3) print(p_result,r_result) 5 None 5 function안에서 결과를 return하게 되면 외부에서 function으로부터 정보를 얻을 수 있다. // return은 function을 종료한다 def r_plus(a, b): return a + b print("sdbfjahggjfdajfajkask",True) //실행x r_result = r_plus(2,3) print(r_result) 5 return 다음 print는 실행되지 않는다, 파이썬에서 뭔가를 return하면 그 function..

Python 2021.11.18

[Python]함수(Function)

//int ( ) function 사용해서 string변수 정수로 변환하기 age = "18" print(age) print(type(age)) n_age= int(age) print(n_age) print(type(n_age)) 18 18 //function정의하기 def say_hello(): print("hello") print("bye") say_hello() hello bye 파이썬에서는 indentation(들여쓰기)로 function의 시작과 끝을 판단(중괄호를 쓰지 않음) 들여쓰기로 function의 안(body)이라는 것을 표시 할 수 있다 function의 이름 뒤에 ( )를 추가하면 function을 실행 하는 것(say_hello를 출력) function의 body는 들여쓰기로 구분..

Python 2021.11.18

[Python]튜플과 딕셔너리(Tuple and Dictionary)

list : common and mutable sequence operations 두가지 모두 가능, 수정 가능 Tuple : common operations만 가능, 수정 불가능 days = ("Mon", "Tue", "Wed", "Thur", "Fri") print(type(days)) list와 같지만 변경할 수 x Jihye = { "name" : "Jihye", "age" : 20, "korean" : True, "fav_food" : ["pasta", "icecream"] //dictionary안 list사용 } print(Jihye) //dictionary 만들기(중괄호 사용) { "name" : "jihye","age" : 20,"korean" : True,"fav_food" : ["pas..

Python 2021.11.18
반응형