잠 못 드는 개발자
close
프로필 배경
프로필 로고

잠 못 드는 개발자

  • 분류 전체보기 (152)
    • Front-end (45)
      • HTML (25)
      • CSS (6)
      • JavaScript (7)
      • React (7)
    • Back-end (21)
      • SQL (2)
      • JAVA (13)
      • Spring (2)
      • Flask (4)
    • AI (64)
      • Python (32)
      • 모두의 딥러닝 (24)
      • NLP (7)
    • Android (5)
    • Git & Github (7)
    • IT 지식 (3)
    • Lecture (8)
  • 홈
  • 태그
  • 방명록
  • 글쓰기

[Python] 11-3장 객체 응용(Ball 클래스, TV 클래스 생성 등)

- Ball 클래스(터틀 그래픽) from turtle import * class Ball(Turtle): def __init__(self, color, speed, size): self.turtle = Turtle() self.turtle.shape("circle") self.x = 0 self.y = 0 self.color = color self.turtle.color(color, color) self.xspeed = speed self.yspeed = speed self.size = size def move(self): self.x += self.xspeed self.y += self.yspeed self.turtle.goto(self.x, self.y) ball = Ball("red", 1, 2)..

  • format_list_bulleted AI/Python
  • · 2023. 4. 11.
  • textsms

[Python] 11-2장 매직 메소드(__str__()), self, 객체 안의 객체, 상속

__str__() 메소드 - 객체의 데이터를 문자열로 변환할 때 사용 - print(인스턴스) 출력할 때 자동적으로 호출됨 class Car: def __init__(self, speed, color, model): self.speed = speed self.color = color self.model = model def drive(self): self.speed = 60 def __str__(self): msg = "속도 = "+str(self.speed)+" 색상 = "+self.color+" 모델 = "+self.model return msg myCar = Car(0, "red", "SUV") print(myCar) # 속도 = 0 색상 = red 모델 = SUV - 참고로 __str__() 메소..

  • format_list_bulleted AI/Python
  • · 2023. 4. 11.
  • textsms

[Python] 11-1장 객체 - 생성, 사용, 초기화(__init__() 생성자)

객체 - 객체는 속성(변수)과 동작(메소드)을 가진 하나로 묶음 객체 = 변수 + 함수(메소드) 객체 생성 1. 클래스(객체의 설계도) 정의 : 객체가 가지고 있는 속성을 변수로 표현, 객체의 동작은 메소드로 정의 class 클래스이름: # 변수 생성 # 메소드 정의 class Car: # Car라는 이름의 클래스 생성 def drive(self): # drive 메소드 생성 self.speed = 10 2. 객체 생성 인스턴스 = 클래스() myCar = Car() 3. 속성(변수) 추가 인스턴스.속성 = 값 myCar.speed = 0 myCar.color = "red" myCar.model = "SUV" 4. 객체의 속성과 메소드 사용 print("자동차의 속도는",myCar.speed) # 자동차..

  • format_list_bulleted AI/Python
  • · 2023. 4. 11.
  • textsms

[Python] 10-3장 파일 입출력 응용(행맨, 파일 안의 문자열 삭제, 빈도수 세기 등)

- 파일에서 단어 읽기 infile = open("C:\\Users\\Desktop\\happy.txt", "r") for line in infile: line = line.rstrip() word_list = line.split() for word in word_list: print(word) infile.close() - 파일 복사 infilename = input("기존 파일 이름: ") outfilename = input("복사된 파일 이름: ") infile = open(infilename, "r") outfile = open(outfilename, "w") s = infile.read() outfile.write(s) infile.close() outfile.close() shutil 모듈 사..

  • format_list_bulleted AI/Python
  • · 2023. 4. 11.
  • textsms

[Python] 10-2장 객체 출력(pickle, dump(), load())

pickle 모듈 - 프로그램 상에서 우리가 사용하고 있는 객체를 파일 형태로 저장하기 위해 필요한 모듈 - pickle을 사용하기 위해서는 항상 binary 타입 정의해야 함 dump() - 객체를 pickle 모듈로 압축 1. pickle 모듈 포함 2. 객체 생성 3. open() 함수 사용하여 "wb"(이진파일 쓰기) 모드로 파일 열기 4. dump() 함수 호출로 객체 전달 5. 파일 닫기 import pickle # 딕셔너리 gameOption = { "sound":8, "videoQuality":"HIGH", "money":10000, "weaponList":["gun", "missile", "knife"] } # 이진 파일 오픈 file = open("C:\\Users\\Desktop\\s..

  • format_list_bulleted AI/Python
  • · 2023. 4. 10.
  • textsms

[Python] 10-1장 파일 다루기(open, close, read, write), 파일 모드(r, w, a, r+)

실습용 텍스트 파일 - 메모장에 아래 내용 작성 후 바탕화면에 profile.txt로 저장하였다 홍길동 Korean 슈퍼맨 American 셜록 홈즈 British 파일 열기(open) - 파일을 사용하려면 우선 파일을 열어야 함 - 파일 이름을 받아서 파일 객체를 생성한 후 반환 - 파일을 여는 데 실패하면 None 객체 반환 파일 객체 = open(파일이름, 파일모드) # 바탕화면에 있는 profile.txt라는 이름의 파일을 읽기 모드로 열기 infile = open("infile = open("C:\\Users\\Desktop\\profile.txt", "r") ※ 파일 경로의 백슬래시 사용할 때는 반드시 \\ 두번 넣어줘야 함 파일 모드(r, w, a, r+) "r" 읽기 모드(read mode..

  • format_list_bulleted AI/Python
  • · 2023. 4. 10.
  • textsms

[Python] 8-4장 리스트, 딕셔너리 응용(영한 사전, 주사위 빈도 계산 등)

- 편의점 재고 관리 items = {"커피음료":7, "펜":3, "종이컵":2, "우유":1, "콜라":4, "책":5} item = input("물건의 이름을 입력하시오: ") print(items[item]) - 영한 사전 dict = {} dict['one'] = '하나' dict['two'] = '둘' dict['three'] = '셋' word = input("단어를 입력하시오: ") print(dict[word]) - 입력받은 숫자들의 평균 numlist = [] sum = 0 for i in range(5): num = int(input("정수를 입력하시오: ")) numlist.append(num) sum += numlist[i] result = sum / len(numlist) pri..

  • format_list_bulleted AI/Python
  • · 2023. 4. 7.
  • textsms
  • navigate_before
  • 1
  • 2
  • 3
  • 4
  • navigate_next
공지사항
전체 카테고리
  • 분류 전체보기 (152)
    • Front-end (45)
      • HTML (25)
      • CSS (6)
      • JavaScript (7)
      • React (7)
    • Back-end (21)
      • SQL (2)
      • JAVA (13)
      • Spring (2)
      • Flask (4)
    • AI (64)
      • Python (32)
      • 모두의 딥러닝 (24)
      • NLP (7)
    • Android (5)
    • Git & Github (7)
    • IT 지식 (3)
    • Lecture (8)
최근 글
인기 글
최근 댓글
태그
  • #문법
  • #모두의 딥러닝
  • #파이썬
  • #두근두근파이썬
  • #HTML
  • #딥러닝
  • #인공지능
  • #태그
  • #PYTHON
  • #속성
전체 방문자
오늘
어제
전체
Copyright © 쭈미로운 생활 All rights reserved.
Designed by JJuum

티스토리툴바