도시정보체계론 3/16 출석 대체 과제
3월 16일 수업의 출석 대체 과제로 Navin Reddy 강사가 진행하는 Python tutorial 강의를 #0~30까지 들었다.
파이썬은 현재도 사용하고 있는 프로그래밍 언어이고,
학부 때 수업도 들어서 마냥 낯설지만은 않다.
이번에 들었던 강의는 tutorial이라 아주 새로운 내용이 나오진 않았다.
따라서, 예전에 배웠던 내용들을 상기시키는 방향으로 학습을 진행했다.
#3 Getting Started with Python
#4 Variables in Python
#5 List in Python
append, insert(index number, value), remove(value), pop(index number), clear, del, extend, min, max, sum, sort
#6 Tuple, Set
in tuple, we cannot change the values
in set, it will not the maintain sequence
#7 Python Set Path in Windows and Help
이 방법은 사용하지 않았다. cmd에서 환경변수를 설정해서 파이썬을 실행하는 방법에 대해 알려준다.
파이썬을 처음 접했을 때 이 방법을 썼는데, 현재는 아나콘다 가상환경을 사용 중이기 때문에 간단히 시청만 했다.
#8 sublime
#9 More on Variables in Python
id()를 이용하면 변수의 address를 알 수 있다
whenever you create multiple variables,and in case if they have the same data they both will point to the same box
address는 변수의 이름에 주어지는 것이 아니라, it is based on the box itself. 즉 value를 담고있는 박스에 주어지는 것이다.
whenever you have a data in your memmory which will not be used or which is not tagged by any variable it will be garbage collector later
#10 Data Types in Python
None: 변수가 할당되지 않음 like a 'null'
Numeric --> int, float, complex, bull
Sequence --> List, Tuple, Set, String, Range, Dictionary
#11 Operators in Python
1. Arithmetic operator: 사칙연산
2. Assignment operator: =, x+=2(shortcut), X*=3
3. Unary operator: negative sign
4. Reloational operator: a<b, a==b, a!=b, returns T/F
5. Logical operator: and, or
#12 Number System Conversion in Python
bin(): decimal --> binary
0b(binary), 0o(octal), 0x(Hexadecimal)
코드를 짤 때, 직접적으로 2진법이나 8진법을 사용해본적이 없어서
과연 어떤 상황에서 필요할지 궁금하다.
#13 Swap 2 Variables in Python
a = 5
b = 6
temp = a
a = b
b = temp
a = a + b # 11
b = a - b # 5
a = a - b # 6
a,b = b,a
#14 IDLE Previous Command | Clear Screen?
#15 Python BitWise Operators
~12 complement of 12 보수
#16 Import Math Functions in Python
#17 Working with PyCharm | Run | Debug | Trace | py file
코드를 .py로 저장하고 실행하는 방법에 대한 강의
파이참에서 debug 기능 사용하기
#18 User input in Python | Command Line Input
외부로부터 데이터 입력받는 방법
x = input()
y = input()
z = x
print(z)
#19 If Elif Else Statement in Python
if 사용하기
#20 While Loop in Python
while loop 사용하기
#21 For Loop in Python
for loop 사용하기
리스트에 있는 요소들을 하나씩 출력하는 예제
--> 아주 간단하지만, 실제 코드에서 정말 많이 쓰이는 것 같음
내 경험에 비춰보면, 실제 코드를 작성할 때, while보단 for을 훨씬 많이 쓰는 것 같음
#22 Break Continue Pass in Python
break, continue, pass
continue: skip the remaining stuff
for i in range(1,101):
if % 3 == 0:
continue #아래의 print 코드를 진행하지 않음
print(i)
print("Bye")
#23 Printing Patterns in Python
#24 For Else in Python
in python, we can use 'for' and 'else' together
nums = [12,16,18,21,26]
for num in nums:
if num % 5 == 0:
print(num)
break
else:
print("not found")
#25 prime Number in Python
주어진 수가 prime number인지 판별하는 코드 짜기
n을 2부터 1씩 수를 증가시켜 n까지 나눠준다.
2~n 사이에 나머지가 0이 되는 숫자가 존재하면 n은 prime number가 아님.
num = 7
for i in range(2,num):
if num % i == 0:
print("Not prime number")
else:
print("Prime")
#26 Array in Python
list는 크기가 가변적이고 원소의 type을 통일할 필요가 없음.
array는 같은 type의 원소만 저장할 수 있는 대신, list에 비해 메모리를 훨씬 적게 씀.
#27 Array values from User in Python Search in Array
1. Accepting values from user and store them in Array in python
-->input()과 array.append를 사용
2. Creating blank array
--> arr = array('i', [])
3. Asking length of array from user and accepting the values
--> n = int(input()) 여기에서 n 값을 for문의 range로 사용해서 값을 append해줌
#28 Why Numpy? Installing Numpy in Pycharm
행렬 연산을 위한 핵심 라이브러리
다차원 배열과 행렬 연산에 필요한 다양한 함수를 제공
#29 ways of Creating Arrays in Numpy
how to create array
array(), linspace(), logspace(), arange(), zeros(), ones()
#30 Copying an Array in Python
array의 각 원소값에 cos(), log(), sin() 모듈을 이용해서 계산해보기
변수가 달라도 데이터 값이 같으면 address값은 하나
.copy()를 이용해서 array copy해보기