x =[1,2,3,4]
if 5 in x :
print("hh")
else :
print("rr")
# tuple() , 안에 값 변경 불가
# dict(), key, value 값으로 설정, 원래 값 변경, 추가 가능
# list(), 안에 값 변경 가능, 추가
num = ["사과","사과","바나나","바나나","딸기"]
d = {}
for n in num:
if n in d:
d[n] = d[n] +1
else :
d[n] = 1
print(d)
# {'바나나':2, '사과':2 , '딸기':1}
class
class Person:
name = "이종민"
def say_hello(self):
print("안녕!" + self.name)
p = Person()
p.say_hello();
class Person:
def __init__(self,name):
self.name = name
def say_hello(self):
print("안녕!" + self.name)
w = Person("w")
p = Person("i")
w.say_hello()
p.say_hello()
# 안녕!w
# 안녕!i
class Person:
def __init__(self,name):
self.name = name
def say_hello(self,to_name):
print("안녕!" + to_name + "나는" + self.name)
w = Person("w")
p = Person("i")
w.say_hello("철수")
p.say_hello("영희")
# 안녕! 철수 나는 w
# 안녕! 영희 나는 i
class Person:
def __init__(self,name,age):
self.name = name
self.age = age
def say_hello(self,to_name):
print("안녕!" + to_name + "나는" + self.name)
def introduce(self):
print("내이름은 " + self.name + "그리고 나이는" + str(self.age))
w = Person("종민",20)
w.introduce()
# 내이름은 종민 그리고 나이는 20
상속!
class Person:
def __init__(self,name,age):
self.name = name
self.age = age
def say_hello(self,to_name):
print("안녕!" + to_name + "나는" + self.name)
def introduce(self):
print("내이름은 " + self.name + "그리고 나이는" + str(self.age))
class Police(Person): # 상속할떄 이렇게 넣어 준다. Person 함수 다 사용 가능..
def arrest ( self, to_arrest):
print("넌 체포됐어"+ to_arrest)
class Programmer(Person):
def program(self, to_program):
print("다음에는 뭘 만들지?" + to_program)
chars = Person("워니",20)
jenny = Police("제니",21)
michael = Programmer("마이클",22)
jenny.introduce()
michael.introduce()
jenny.arrest("종민")
michael.program("앱")
# 내이름은 제니 그리고 나이는 21
# 내 이름은 마이클 그리고 나이는 22
# 넌 체포됐어종민
# 다음에는 뭘 만들지? 앱
package == 라이브러리라고 한다. ( 모듈들의 합 )
modul == 코드 들어있는 파일 ( 이 코드가 모여서 어떤 한 기능을 구현함 )
파일을 만들고 그 파일안에 class 구현
# cat.py
class Cat:
def hi(self):
print("meow")
# dog.py
class Dog:
def hi(self):
print("dock")
# 해당 모듈들 불러오는 방법
# __init__.py 안에 있는 것들
from .cat import Cat # . <- "이 폴더에 있는" cat.py 이라는 파일에서 Cat 이라는 클래를 갖고와주
from .dog import Dog
'알고리즘' 카테고리의 다른 글
[알고리즘] Python 기초.3 (0) | 2020.03.21 |
---|---|
[알고리즘] Python 기초.2 (0) | 2020.03.21 |
[ 알고리즘 ] 주제 목차들 (0) | 2019.10.11 |
[ 알고리즘 ] Sort 정리 (0) | 2019.10.09 |
[ 알고리즘 ] 그래프( 재귀 함수 ) (0) | 2019.10.06 |
댓글