파이썬

import numpy as np numbers = [1, 2, 3, 4, 5] print(numbers) numbers2 = [] for i in range(1,6): numbers2.append(i) print(numbers2) # List comprehension numbers3 = [n for n in range(1,6)] print(numbers3 ) 실행결과[1][1, 2, 3, 4, 5][1, 2][1, 2, 3, 4, 5][1, 2, 3][1, 2, 3, 4, 5][1, 2, 3, 4][1, 2, 3, 4, 5][1, 2, 3, 4, 5][1, 2, 3, 4, 5] # 2, 4, 6, 8, 10 even = [2 * n for n in range (1,6)] print(even) 실행결과[..
Python 반복문 - for 구문for 변수 in Iterable: 반복할 문장들 Iterable(반복 가능한 타입) : list, tuple, set, dict, str, ... # range(to): 0부터 (to -1)까지 범위의 숫자들# range(from,to): from부터 (to -1)까지 범위의 숫자들# range(from, to, step): from부터 (to -1)까지 step만큼씩 증가 for i in range(5): print(i) 실행 결과01234 for i in range(5): # (0, 1, 2, 3, 4) print(i, end = ' ') 실행 결과0 1 2 3 4 for i in range(1,7): # (1, 2, 3, 4, 5, 6) print(i, end =..
Python if 구문(statement)1if 조건식: 조건식이 참일 때 실행할 문장 2if 조건식: 참일 때 실행할 문장else: 거짓일 때 실행할 문장 3if 조건식1: 조건식1이 참일 때 실행할 문장elif 조건식2: 조건식2가 참일 때 실행할 문장...else: 조건식이 모두 거짓일 때 실행할 문장 # 숫자를 입력받아서 양수인 경우에만 출력 num = float(input(">>> 숫자를 입력: ")) if num>0: print(f'num = {num}') print('프로그램 종료') 실행 결과 # 숫자를 입력받아서 양수인 경우에만 출력 num = float(input(">>> 숫자를 입력: ")) if num>0: print(f'num = {num}') if num>0: print('양수'..
dict: key-value의 쌍으로 이루어진 데이터들을 저장하는사전(dictionary)식 데이터 타입 person = {'name': '모쌤', 'age': 16, 'height': 170.5 } print(person) print(type(person)) 출력 결과{'name': '모쌤', 'age': 16, 'height': 170.5} # dict의 데이터 참조 - key 이용 print(person['name']) print(person['age']) 출력 결과모쌤16 # dict의 key를 알아낼 때 print(person.keys()) # dict의 value를 알아낼 때 print(person.values()) 출력 결과dict_keys(['name', 'age', 'height'])di..
Codezoy
'파이썬' 태그의 글 목록 (4 Page)