반응형
- 출력하는 코드:
python
print("안녕하세요!")
- 문자열 조작 코드:
python
s = "뤼튼입니다"
s_upper = s.upper()
print(s_upper)
- 리스트 정렬 코드:
python
numbers = [3, 1, 4, 2]
sorted_numbers = sorted(numbers)
print(sorted_numbers)
- 함수 생성 코드:
python
def add(a, b):
return a + b
result = add(3, 4)
print(result)
- 클래스 생성 코드:
python
class Dog:
def __init__(self, name, age):
self.name = name
self.age = age
def bark(self):
print(f"{self.name}이(가) 짖습니다: 멍멍!")
my_dog = Dog("날라", 3)
my_dog.bark()
- 웹 크롤링 코드 (BeautifulSoup 라이브러리 사용):
python
import requests
from bs4 import BeautifulSoup
url = "https://news.google.com/"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
headlines = soup.find_all("h3")
for headline in headlines:
print(headline.text)
- 웹 서버 구축 코드 (Flask 라이브러리 사용):
python
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def home():
return render_template("index.html")
if __name__ == "__main__":
app.run(debug=True)
반응형
'생각 > 파이썬 , R' 카테고리의 다른 글
파이썬 라이브러리와 예시 (0) | 2023.06.20 |
---|---|
파이썬 기초 문법 (1) | 2023.06.19 |
[TIL] 2022.12.04 (0) | 2022.12.04 |
[파이썬 R 데이터 분석 1강] (1) | 2022.09.25 |