[Python]노마드코더_web scraper_개념

3200 단어 pythonTILTIL

노마드 코더 web scraper 만들기 시작!
https://nomadcoders.co/python-for-beginners

💡variables(변수)

a = 2 , b = 3

💡Data type

  1. str(string):문자
  2. int(integer):정수
  3. boolean: True or False
  4. float:소수
  5. none : none
ex)
1. a_string = "like this"
2. a_int = 3
3. a_boolean = False 
4. a_float = 3.14
5. a_none = None 

Data type을 확인하고 싶을때 type함수를 쓴다.
print(type(a_int)) 👉<class red,'int'>


💡lists

-대괄호 안에 value를 ""안에 넣어 정렬한다.
-언제든 다양하게 변경할 수 있다!

ex>
days = ["Mon","Tue","Wed","Thur","Fri"]
print(days)

list에 항목더하기

days.append("Sat")
print(days)
결과 
["Mon","Tue","wed","Thur","Fri","Sat"]

항목 거꾸로 나열

days.reverse()
print(days)
결과
["Sat","Fri","Thur","wed","Tue","Mon"]

💡Tuples and Dicts

📜tuple

-변경이 불가능하다
-리스트의 []를 ()로 바꾸면 된다.

📜Dictionary

-key와 value
-{}사용

ex)
nico = {
  "name" : "Nico",
  "age" : 29,
  "korean" : True,
  "fav_food" : ["kimchi","sasimi"]
}
print(nico)
결과
'name': 'Nico', 'age': 29, 'korean': True, 'fav_food': ['kimchi', 'sasimi']

딕셔너리 추가

nico["handsome"] = True
print(nico)
결과
'name': 'Nico', 'age': 29, 'korean': True, 
'fav_food': ['kimchi', 'sasimi'], 'handsome': True

💡Function Arguments

-함수 만드는 법 ()

-function의 argument(인자)에 input 주기

-function이름 뒤에 ()를 추가하면 function 실행

-()괄호 안에 디폴트 값을 넣을 수 있다.

-디폴트 값이 없는 경우는 외부에서 input을 받아서 사용

def say_hello(name = "anonymous"):
  print("hello",name)
say_hello("hyeyoon")

결과
hello,hyeyoon

💡Return

1. 값을 return

2. function 종료

def plus(a,b):
	return a + b
result = plus(2,4)
print(result)

결과
6

💡Keyworded Arguments

formatting

1. string 안에 {변수}넣기

2. ""앞에 f를 붙여 변수 실행

def say_hello(name,age):
	return f"Hello {name} you are {age} years old"
hello = say_hello("nico","15")
print(hello)
결과
Hello nico you are 15 years old

def say_hello(name, age):
return "Hello " + name + " you are " + age + " years old"
이 방법도 가능하다!


💡for문의 구조

for 변수 in 문자열, 리스트, 튜플

-for 반복문은 in 뒤에 존재하는 문자열, 리스트, 튜플을 순서대로 순회하면서 하나씩 하나씩 변수에 넣어준다.
-for문의 끝에는 꼭 콜론 ( : ) 을 붙여주어야 한다.
-for 반복문에 [수행부분]이 속해있다는것을 들여쓰기를 통해 나타낸다.
-for문을 중첩해서 사용 할수도 있습니다
ex)
days = ("mon","tue","wed","thu","fri")
for day in days:
if day is "wed":
  break
else:
   print(day)

좋은 웹페이지 즐겨찾기