a = 123
b = -178
c = 0
print(type(a))
print(type(b))
print(type(c))
d = 1.2
e = -3.45
print(type(d))
print(type(e))
## 정수형 * 실수형은? 실수형!
f = a*d
e = c*e
print(type(f))
print(type(e))
+
, -
, *
, /
)**
)%
)//
)# 나눗셈 연산자 % , //
# / 는 결과 그대로
print("/ : {}".format(7/4))
print("// : {}".format(7//4))
print("% : {}".format(7%4))
<문자열 표현 방법>
<문자열 타입 확인 및 큰따옴표 작은따옴표 차이 비교>
string_test = "Hello World"
type(string_test)
# 만약 문자열 안에 작은따옴표 또는 큰 따옴표를 넣고 싶다면?
string_test = "Python's favorite food is perl"
string_test
<문자열 줄바꿈>
string_test = "Life is too short\n You need python"
print(string_test)
string_test= """
Life is too short
sdsdsds
You need python
"""
print(string_test)
<문자열 연산>
a = "python"
a*3
print("=" * 50)
print("My Program")
print("=" * 50)
<문자열 인덱싱>
a = "Life is too short"
len(a)
print(a[16])
print(a[0:4])
print(a[0] + a[1] + a[2] + a[3])
<문자열 관련 함수>
# 문자 개수 세기
a = "hobby"
a.count('b')
# 위치 알려주기
a = "Python is the best choice"
a.find('y')
# 문자열 삽입
",".join('abcd')
# 소문자를 대문자로
a = "hi"
a.upper()
#대문자를 소문자로
a = "HI"
a.lower()
# 문자열 나누기
a = "Life,is,too,short"
int_list = a.split(",")
int_list
# 문자열 나누기
a = "서울시 동작구"
int_list = a.split(" ")
int_list[1]
<리스트 기본 구조>
a = []
b = [1, 2, 3]
c = ['Life', 'is', 'too', 'short']
d = [1, 2, 'Life', 'is']
e = [1, 2, ['Life', 'is']]
<리스트 슬라이>
a[0:3]
a[:]
a[2:]
<리스트 연산하기>
a = [1,2,3]
b = [4,5,6]
a+b
a*2
<리스트 관련함수>
# 리스트 추가하기
a = [1, 2, 3]
a.append(5)
a
# 리스트 정렬
a = [1, 4, 3, 2]
a.sort()
a
# 리스트 정렬
a.sort(reverse=True)
a
# 요소 삽입
a = [1, 2, 3]
a.insert(0, 4)
a
# 요소 제거하기
a = [1, 2, 3, 1, 2, 3]
a.remove(3)
a
# 갯수 세기
a = [1, 2, 3, 1]
a.count(1)
<딕셔너리 기본 구조>
dic = {'name': 'pey', 'phone': '010-9999-1234', 'birth': '1118'}
<딕셔너리 추가 삭제하기>
# 추가하기
a = {1: 'a'}
a[2] = 'b'
a
# 삭제하기
del a[1]
a
<딕셔너리 관련 함수들>
a = {'name': 'pey', 'phone': '010-9999-1234', 'birth': '1118'}
a.keys()
a.values()
for k in a.keys():
print(k)
items = my_dict.items()
print("Items:", items) # 출력: dict_items([('name', 'John'), ('age', 30), ('city', 'New York')])
# Boolean 변수 선언
is_raining = True
is_sunny = False
# 비교 연산자를 사용하여 Boolean 값 비교
x = 10
y = 5
greater_than = x > y
print(greater_than) # True 출력
💡 변수의 주소, 타입, 메모리 확인하기
import sys
# 변수 선언
int_var = 1
float_var = 3.14
str_var = "Hello"
# 변수의 자료형 출력
print(f"Type of int_var: {type(int_var)}")
print(f"Type of float_var: {type(float_var)}")
print(f"Type of str_var: {type(str_var)}")
# 변수의 메모리 주소 출력
print(f"Memory address of int_var: {id(int_var)}")
print(f"Memory address of float_var: {id(float_var)}")
print(f"Memory address of str_var: {id(str_var)}")
# 변수의 메모리 사용량 출력
print(f"Memory size of int_var: {sys.getsizeof(int_var)} bytes")
print(f"Memory size of float_var: {sys.getsizeof(float_var)} bytes")
print(f"Memory size of str_var: {sys.getsizeof(str_var)} bytes")