print("Hello World!")
"""
Hello World
Hello Python
안녕하세요?
"""
print("Hello World!")
a = 10 #10이 만들어지고, a가 10을 가리킨다
b = a #b가 10을 가리킨다
print(a)
print(b) #a, b는 모두 10을 가리킨다
b = 20 #20이 만들어지고, b가 20을 가리킨다
print(b)
print(a) #a에는 아무 영향이 없으므로, 원래 a가 가리키던 값이 출력된다
a = 10 #정수 - int
pi = 3.14 #실수 - float
comp = 1+2j #복소수 - complex number
type(a)
type(pi)
type(comp)
#문자열을 만드는 4가지 방법
a = "Hello World"
b = 'Hello World'
c = """Hello World"""
d = '''Hello World'''
print(a)
print(b)
print(c)
print(d)
a = "apples"
"I like %s." % a
a, b = "apples", "bananas"
"I like %s and %s" % (a,b)
True
False
a = None
print(a)
a = 3.0
type(a)
a = int(a)
type(a)
squares = [1, 4, 9, 16, 25]
squares
a = [1, 2, 3, [4, 5]]
a[3] #인덱스 3번 값 출력
a[3][0] #인덱스 3번 값 중 0번째 인덱스 출력
squares[:3]
squares[3:]
a = [1, 2, 3]
b = [4, 5, 6]
a+b
len(a)
len(a+b)
a = [1, 2, 3, 4, 5]
a[2] = '짝!'
a
del a[2]
a
10 == 10
9 != 10
9 < 10
10 > 9
9 <= 9
9 >= 9
True and True
False or True
not True
a = 10 #a에 10이라는 값을 할당한 후,
if a == 10:
print("a는 10이다.")
elif a == 11:
print("a는 10은 아니지만 11이다.")
else:
print("a는 10도 11도 아니다.")
# for 변수 in 리스트 혹은 튜플, 문자열:
# 실행할 코드
scores = [90, 100, 50, 25, 70, 60, 65]
for score in scores:
print("%a점에 대한 합격여부 판단" % score)
if score >= 70:
print("합격")
else:
print("불합격")
for i in range(5):
print(i)
for i in range(1, 10): #1부터 10까지
print(i)
for i in range(1, 10, 2): #1부터 10까지 2씩 끊어서
print(i)
for i in range(10, 1, -2): #10부터 1까지 역순으로 2씩 끊어서
print(i)
# while 조건문:
# 실행할 코드
count = 1
while count < 10:
print("Count: %d" % count)
count += 1
for i in range(1, 10):
print(i)
if i == 3:
break #i가 3이 되면 중간에 반복문 빠져나오기
print(i)
for i in range(1, 10):
print(i)
if i == 3:
continue #i가 3이 되면 해당 순차 건너뛰기
print(i)
a = 10
if a == 10:
print("a는 10이다.")
elif a == 11:
print("a는 10은 아니지만 11이다.")
else:
print("a는 10도 11도 아니다.")
def detect_10_or_11(number):
if number == 10:
print("number는 10이다.")
elif number == 11:
print("number는 10은 아니지만 11이다.")
else:
print("number는 10도 11도 아니다.")
detect_10_or_11(11)
detect_10_or_11(100)
# def 함수명(매개변수 혹은 전달인자):
# 실행할 명령어1
# 실행할 명령어2
# ...
# return 리턴값
def hello(name): #name - 매개변수
print("Hello, %s" % name) # name - 매개변수
hello("joy") #joy - 전달인자