왜 날이 갈수록 더 피곤해지는지는 모르겠다만..
코로나가 낫는지 안낫는지 도무지 모르겠다
아예 아무것도 안하기에는 너무 불안해서 아픈 몸 이끌고 공부하러..
어제부터 오늘까지는 파이썬 기본이니 부담없이 해야겠당ㅎ
'값.메서드명()'
ex)
alphabet = ["a","b","c","d","e"]
alphabet.append("F")
print(alphabet)
##output :
['a','b','c','d','e','F']
변수.upper()
변수.count("객체")
city = "Tokyo"
print((city.upper())
print(city.count("o"))
##output :
TOKYO ##upper메서드를 통해 대문자로 바뀌었으므로
2 ##count메서드를 통해 문자 o의 개수를 카운트한다.
print("나는 {}에서 태어나 {}에서 유년기를 보냈습니다.".format("서울","광명시"))
##output :
나는 서울에서 태어나 광명시에서 유년기를 보냈습니다.
alphabet = ["a","b","c","d"]
print(alphabet.index("a"))
print(alphabet.count("d"))
##output :
0 ##a의 인덱스 번호 0을 출력
2 ##d가 alphabet내에서 2번 언급
list = [1,10,2,20]
list.sort()
print(list)
##output :
[1,2,10,20]
##list.sort()를 이용하여 오름차순 정렬
1) 함수 작성법 :
def 함수명(인수) :
2) 함수 호출법 :
함수명()
##문제 : "홍길동입니다." 라고 출력하는 함수 introduce를 작성하라.
출력은 print()함수를 사용하라.
sol)
def introudce() :
print("홍길동입니다."
1) 인수가 하나인 함수 예제 :
def introduce(n) :
print(n+"입니다.")
##함수 선언
introduce("홍길동")
##함수호출
##output :
홍길동입니다.
2) 인수 n을 세제곱한 값을 출력하는 함수 cube_cal을 작성하라.
def cube_cal(n) :
print(n**3)
cube_cal(4)
##output : 64 (4*4*4)
'함수명(인수)' , 인수 = 초깃값
ex) 인수의 초깃값 예 :
def introduce (first = "김", second = "길동") :
print("성은" + first + "이고 ," + "이름은 " + second + "입니다.")
introduce ("홍")
##output :
성은 홍이고 , 이름은 길동입니다.
'return 반환값'
def introduce (first = "김", second = "길동") :
return ("성은" + first + "이고 , 이름은" + second+ "입니다."
print(introudce("홍"))
#output :
성은 홍이고, 이름은 길동입니다.
혹은
def introudce (first = "김", second = "길동") :
comment = "성은" + first + "이고, 이름은" + second + "입니다."
return comment
print(introduce("홍"))
#output :
성은 홍이고 이름은 길동입니다.
import time
##time 패키지를 불러온다.
now_time = time.time()
##time 모듈을 사용하여 현재 시간을 now_time에 대입한다.
print(now_time)
##현재 시간 출력
from time import time
now_time = time()