[Python] 기초 문법 공부
a=2
b=3
print(a+b) #5
first_name = 'sanghyun'
last_name = 'jang'
print(first_name + last_name) # sanghyunjang
a_list = ['사과', '배', '감']
a_list.append('수박')
print(a_list) #['사과', '배', '감', '수박']
a_dict = {'name' : 'bob', 'age' : 27}
print(a_dict['name']) #bob
a_dict['height'] = 179
print(a_dict) #{'name': 'bob', 'age': 27, 'height': 179}
def sum(num1, num2):
print('안녕!')
return num1+num2
result = sum(2,3)
print(result) # 안녕! 5
age = 25
if age > 20:
print('성인입니다')
else:
print('청소년입니다')
#성인입니다
def is_adult(age):
if age > 20:
print('성인입니다')
else:
print('청소년입니다')
is_adult(30) #성인입니다
is_adult(15) #청소년입니다
fruits = ['사과','배','배','감','수박','귤','딸기','사과','배','수박']
count = 0
for ff in fruits:
if ff == '수박':
count += 1
print(count) #2
people = [
{'name': 'bob', 'age': 20},
{'name': 'carry', 'age': 38},
{'name': 'john', 'age': 7},
{'name': 'smith', 'age': 17},
{'name': 'ben', 'age': 27}
]
for person in people:
if person['age'] < 20:
print(person)
a=2
b=3
print(a+b) #5
first_name = 'sanghyun'
last_name = 'jang'
print(first_name + last_name) # sanghyunjang
a_list = ['사과', '배', '감']
a_list.append('수박')
print(a_list) #['사과', '배', '감', '수박']
a_dict = {'name' : 'bob', 'age' : 27}
print(a_dict['name']) #bob
a_dict['height'] = 179
print(a_dict) #{'name': 'bob', 'age': 27, 'height': 179}
def sum(num1, num2):
print('안녕!')
return num1+num2
result = sum(2,3)
print(result) # 안녕! 5
age = 25
if age > 20:
print('성인입니다')
else:
print('청소년입니다')
#성인입니다
def is_adult(age):
if age > 20:
print('성인입니다')
else:
print('청소년입니다')
is_adult(30) #성인입니다
is_adult(15) #청소년입니다
fruits = ['사과','배','배','감','수박','귤','딸기','사과','배','수박']
count = 0
for ff in fruits:
if ff == '수박':
count += 1
print(count) #2
people = [{'name': 'bob', 'age': 20},
{'name': 'carry', 'age': 38},
{'name': 'john', 'age': 7},
{'name': 'smith', 'age': 17},
{'name': 'ben', 'age': 27}]
for person in people:
if person['age'] < 20:
print(person)
'개발 => 복습 후 재정리 대기 > Python' 카테고리의 다른 글
[Python] [문법] 문자열 길이, 자르기, 쪼개기 (0) | 2021.05.05 |
---|---|
[Python] [문법] 사칙연산, 제곱, 나머지 (0) | 2021.05.05 |
[Python] 공백 제거 (0) | 2021.05.03 |
[Python] Crawling 크롤링 실습 (0) | 2021.05.02 |
[Python] requests 패키지 사용연습 (0) | 2021.05.02 |
댓글