1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | #형변환 연습 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 < class 'str' = "" > 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) </ class > |
'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 |