# From-the-base.md

***

python을 주 언어로 선택하고 개발을 쭉 해오면서 기본이 가장 중요하다는 걸 계속 느끼고 있다. 이참에 python의 기초부터 간간히 공부해보려 한다.

## 변수 - Variable

***

* 데이터를 저장하는 공간
* 메모리에 값을 생성하고 이름을 지정
* 대입연산자를 사용하여 값을 대입

```python
a = 1
b = "str"
c = 1.23
```

## 자료형

> **Numeric - 수 자료형**

* 정수형
* 실수형

> 컴퓨터 시스템은 2진수를 사용하여 모든 데이터를 처리한다. 실수를 처리할 때는 **부동소수점방식**을 이용하는데, iEEE754 표준에서는 **4바이트-float, 8바이트-double**의 메모리를 할당하여 대체로 실수 정보를 표현하는 정확도에 한계를 가진다.

```python
a = 0.3 + 0.6
print(a)
if a == 0.9:
    print(True)
else:
    print(False)
```

```
0.899999999999999
False
```

* 따라서 실수형 자료형을 정밀하게 비교해야할 때가 오면 가끔씩 오류가 날 수 있다. 따럿 `round()`함수를 사용하여 반올림하여 사용하자

> **round()** round(number=float, ndigit:int) 두 번째 인자인 ndigit은 \[반올림하고자 하는 위치 -1]을 뜻한다.

* 수 자료형의 연산

```python
a = 12
b = 13

print(a + b) # 25
print(a - b) # -1
print(a * b) # 156
print(a / b) # 0.9230769230769231
print(a // b) # 0 -> 정수형 몫만 반환
print(a ** b) # 106993205379072 -> a^b
print(a % b) # 12
```

> **Str - 문자열**

* 문자열은 건너뛰겠....

> **List - 리스트**

* 인덱싱, 슬라이싱 건너뛰...

> List comprehension - 리스트 컴프리헨션

* 리스트 초기화하는 방법중에 하나로, 대괄호 안에 조건문과 반복문을 넣는 방시으로 리스트를 초기화할 수 있다.

```python
# 0부터 19까지의 수 중에서 홀수만 포함하는 리스트
arr = [i for i in range(20) if i % 2 == 1]
```

* 리스트 관련 메서드

| name      |            description           |   시간 복잡도 |
| --------- | :------------------------------: | -------: |
| `append`  |       리스트 원소 삽입(가장 마지막 인덱스)      |     O(1) |
| `sort`    | 기본 정렬 오름차순(reverse=True => desc) | O(NlogN) |
| `reverse` |           리스트 원소 앞뒤 바꾸기          |     O(N) |
| `insert`  |           특정 인덱스에 원소 삽입          |     O(N) |
| `count`   |       특정한 값 가지는 데이터 개수 셀 때       |     O(N) |
| `remove`  |     특정값 가지는 원소 제거(중복시 하나만 제거)    |     O(N) |

> append() - 리스트 원소 삽입(가장 마지막 인덱스)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://woungsub1234.gitbook.io/woungsub-devlog/programming/python/from-the-base.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
