본문 바로가기

혼공

week1-python

기본미션 - p101 3번, 4번, 5번 문제

 

 

 

5행에서 IndexError

 

 

 

 

 

 

chapter01 - chapter02

 

자료형

nu = 10_000_000                 # 숫자 int float
st = 'three'                    # 문자 chr str
bo = False                      # 불린 bool

li = [1, 2, 3, 4]               # list
tu = (1, 2, 3, 4)               # tuple
se = {1, 2, 3, 4}               # set
di = {'name': 'gy', 'age': 4}   # dict

number

n = 1
print(f"{n:05d}")    # 00001

a = 12.355
print(f"{a:5.1f}")  #  12.4

n = 10
a = 0b1010          # 10, int
b = 0o12            # 10, int
c = 0xA             # 10, int

print(f"{n:b} {n:o} {n:x}")    #   1010   12   a
print(bin(n), oct(n), hex(n))  # 0b1010 0o12 0xa
print(int('1010', 2), int('0b1010', 2))

bool

불 형변환 시 False인 경우: None, 0, 빈 컨테이너 (빈 문자열)

string

st = 'morning'

'n' in st
st.find('n')       
st.count('n')

st.upper()      
st.lower()          
st.strip()         
st.replace('n', '-')

st.isdecimal()           # isdecimal < isdigit < isnumeric
st.isalpha()

li = '1:2:3'.split(':')  # ['1', '2', '3']
st = ':'.join(li)        # 1:2:3

multi_st = (
  "줄이 길어"
  "나누어 적습니다"
)

 

 

 

'혼공' 카테고리의 다른 글

week2-python  (0) 2023.07.16
week2-java  (0) 2023.07.15
week2-javascript  (0) 2023.07.13
week1-java  (0) 2023.07.09
week1-javascript  (0) 2023.07.03