Python 기초 - 함수, 모듈, 클래스

less than 1 minute read

함수, 메서드

  • 내장함수
	print()
	len()
	int()
	str()
	sum((1, 2, 3, 4, 5))
	max((1, 2, 3, 4, 5))
	min([1, 2, 3, 4, 5])
  • 사용자 지정 함수
	def plus(a, b):
		c = a + b
		return c
	print(plus(1,2))
  • 전역변수, 지역변수
    • ㅇㅇ
  • Method
    • 특정 자료에 대해 특정 기능을 하는 코드
    • 는 개뿔 걍 멤버함수라는 거…
	my_list.append()
	my_list.count()
	my_list.pop()

모듈

  • cal.py
	def plus(a, b)
		return a + b
  • main.py
	import cal
	print(cal.plus(1, 2))
  • 패키지
    • 폴더로 관리
	import user.cal
	print(cal.plus(3, 4))

	from user.cal import plus
	print(plus(5,6))

객체

  • 필드
  • 메서드
	class Animal:
		name = "Dongmul"
		age = 0
		def sleep(self):
			print("zzz")

	# 상속
	class Dog(Animal):
		name = "Baduk"
		age = 10
		def bow(self):
			print("DangDang!")

	coco = Dog()

	coco.name = "coco"
	coco.sleep()
	coco.bow()