python2020. 1. 16. 23:24

#형변환 연습

x = 10 
y = '10'


print(chr(65))
print(chr(65+25), ord('Z'))
print(chr(97))

print(ord('가'))

print(bin(16))
#str 리턴 되므로 슬라이싱을 통해 숫자 부분만 리턴 가능
print(bin(16)[2:])
#응용
print(bin(16)[2:].replace('1','#').replace('0','!'))

print(oct(16))
print(hex(16))

print(hex(id(y)))
print(type(hex(id(y))))


x = 0b1101
y = 0o15
z = 0xd

if x == y :
    print('{} is same with {}'.format(x,y))

if x == z :
    print('{} is same with {}'.format(x,z))

    

#same as False
print(bool([]))
print(bool({}))
print(bool(()))
print(bool(0))
print(bool(0.0))
print(bool(''))

#이외의 어떤값이 있다면 True

print(bool(1))
print(bool(-1))
print(bool(' '))
print(bool('a'))


a= [True,False,False] 
b= [True,True,True] 
c= [False,False,False] 
#all 모든 값이 True인 경우 True return
print(all(a))
print(all(b))
print(all(c))

#any 

print(any(a))
print(any(b))
print(any(c))

d = ['', 0, 0.0]
print(all(d))
print(any(d))

"""
A
Z 90
a
44032
0b10000
10000
#!!!!
0o20
0x10
0x226a521f170

13 is same with 13
13 is same with 13
False
False
False
False
False
False
True
True
True
True
False
True
False
True
True
False
False
True
"""

#list, tuple, set ,dict


name = 'jayce'
print(name)
print(tuple(name))
print(set(name))
#print(dict(name)) 불가


#숫자 카운팅
#10000안에 포함된 8의 갯수 세기
str(list(range(10000))).count('2')


#dict

a = dict(one=1,two=2,three=3)
b = {'one':1,'two':2,'three':3}
#리스트로 구성된 key와 value를 dict로 합치는 방법
c = dict(zip(['one','two','three'], [1,2,3]))
d = dict([('two',2), ('one',1), ('three', 3)]) 
e = dict({'one':1,'two':2,'three':3})


#응용
new_dict=dict(zip(a.keys(),a.values()))
print(new_dict)



'python' 카테고리의 다른 글

코루틴 예제  (0) 2020.01.22
클래스 변수, 인스턴스 변수  (0) 2020.01.20
python 가상환경 설정  (0) 2020.01.02
크롤링 연습 11. google sheet에 데이터 저장  (0) 2019.12.27
정규표현식 연습 2. 반복  (0) 2019.12.26
Posted by easy16