- 영작 공부와 python 공부를 한번에 -
Python has three data types of numbers:
1. Integers(정수)
- Integers are whole number that can be positive, negative, or zero.(음수 양수 0 표현 가능)
- They are represented in Python without a decimal point.(소수점x, 정수만)
- They can be of any length up to the available memory in your computer system.(길이 제한x)
2. Floating point numbers(부동 소수점 수)
- They can also be positive, negative, or zero.(음수 양수 0)
- Floating point numbers can repesnt a wider range of values than integer(integer tpye 보단 넓은 range를 커버 가능)
3. Complex number(복소수)
- Complex numbers are numbers with a real part and imaginary part.(실수와 허수를 포함하는 수)
- Imaginary part of complex numbers are represented in python using 'j' or 'J'.
- For example they can express 3.1 + 2.7j or 1.2 - 2J.
Explanation of String data type in Python:
python are not include char data type, but to be able perform similar tasks
1. Concatenation between string types(문자열 끼리의 연결)
- python supports + operator between strings. for example, 'Hi ' + 'python' = Hi python
2. Slicing:(문자 나누기)
- You can extract a portion of a string using slicing. for example, 'Hi python'[3:8] returns 'python'
3. Length:(문자열 길이)
- You can find the length of a string using the len() function
4. Formatting:(문자열의 formatting)
- you can format a string to include values of other data types using the format() method.
for example, 'My name is {} and I am {} years old'.format('Jack', 26) returns
'My name is Jack and I am {} years old'.
5. Other methods
- upper(): this method returns a new string with all the characters in uppercase.(대문자 변환)
- lower(): this method is opposite of upper().(소문자 변환)
- strip(): this method removes any leading or trailing whitespace from a string.(공백 제거)
- replace(): this method replaces all occurrences of a specified substring in string.(문자열 특정 문자 변환)
- split(): this method splits a string into a list of substring based on a specified delimiter.(특정 문자를 기준으로 문자열 나누기)
Explanation of Lists data type in Python:
1. Lists can contain items of defferent data type, including other list:
for example,
my_list = [1, "two", 3.0, ["four", 5]]
- append(): Adds an item to the end of the list.(list맨 뒤에 item추가)
- insert(): Inserts an item at a specific position in the list.(원하는 index에 item추가)
- pop(): Removes and returns the item at a specific position in the list.(원하는 index에서 item추출)
- remove(): Removes the first occurrence of a specified item from the list.(원하는 index의 item삭제)
- sort(): Sorts the items in the list in ascending or descending order.(크기 순서로 정렬 reverse=True면 내림차순)
for example,
my_list = [1, 2, 3, 4, 5]
my_list.append(6)
my_list.insert(3, 3.5)
my_list.pop(0)
my_list.remove(4)
my_list.sort(reverse=True)
print(my_list)
# print => [6, 5, 3.5, 3, 2]
List type's limitations and points to note:(많은 양의 데이터 접근은 deque가 빠르다)
if you need repeatedly remove items from the beginning of a list, it may be more efficient to use a data structure like a deque. (deque is double-ended queue)
'2022 하반기 > Python' 카테고리의 다른 글
백준 1019 python (0) | 2023.02.17 |
---|---|
백준 10815 python (0) | 2023.02.17 |
백준 1931 Python (0) | 2023.02.08 |
백준 11047 Python (0) | 2023.02.07 |
백준 2750 Python (0) | 2023.02.07 |
댓글