| 98 | {{{#!th style="background: #ddd" |
| 99 | '''Label''' |
| 100 | }}} |
| 101 | {{{#!th style="background: #ddd" |
| 102 | '''Python 2''' |
| 103 | }}} |
| 104 | {{{#!th style="background: #ddd" |
| 105 | '''Python 3''' |
| 106 | }}} |
| 107 | |----------------------- |
| 108 | {{{#!td |
| 109 | String: |
| 110 | }}} |
| 111 | {{{#!td |
| 112 | {{{ |
| 113 | >>> 'sample' |
| 114 | 'sample' |
| 115 | }}} |
| 116 | }}} |
| 117 | {{{#!td |
| 118 | {{{ |
| 119 | >>> 'sample' |
| 120 | 'sample' |
| 121 | }}} |
| 122 | }}} |
| 123 | |----------------------- |
| 124 | {{{#!td |
| 125 | Unicode: |
| 126 | }}} |
| 127 | {{{#!td |
| 128 | {{{ |
| 129 | >>> 'sample' |
| 130 | u'sample' |
| 131 | }}} |
| 132 | }}} |
| 133 | {{{#!td |
| 134 | {{{ |
| 135 | >>> 'sample' |
| 136 | 'sample' |
| 137 | }}} |
| 138 | }}} |
| 139 | |----------------------- |
| 140 | {{{#!td |
| 141 | Bytes: |
| 142 | }}} |
| 143 | {{{#!td |
| 144 | {{{ |
| 145 | >>> b'sample' |
| 146 | 'sample' |
| 147 | }}} |
| 148 | }}} |
| 149 | {{{#!td |
| 150 | {{{ |
| 151 | >>> b'sample' |
| 152 | b'sample' |
| 153 | }}} |
| 154 | }}} |
| 155 | |----------------------- |
| 156 | {{{#!td |
| 157 | Types: |
| 158 | }}} |
| 159 | {{{#!td |
| 160 | {{{ |
| 161 | >>> type('xx'), type(u'xx'), type(b'xx') |
| 162 | (<type 'str'>, <type 'unicode'>, <type 'str'>) |
| 163 | }}} |
| 164 | }}} |
| 165 | {{{#!td |
| 166 | {{{ |
| 167 | >>> type('xx'), type(u'xx'), type(b'xx') |
| 168 | (<class 'str'>, <class 'str'>, <class 'bytes'>) |
| 169 | }}} |
| 170 | }}} |
| 171 | |
| 172 | When special characters are involved: |
| 173 | |
| 174 | {{{#!th style="background: #ddd" |
| 175 | '''Label''' |
| 176 | }}} |
| 177 | {{{#!th style="background: #ddd" |
| 178 | '''Python 2''' |
| 179 | }}} |
| 180 | {{{#!th style="background: #ddd" |
| 181 | '''Python 3''' |
| 182 | }}} |
| 183 | |----------------------- |
| 184 | {{{#!td |
| 185 | String: |
| 186 | }}} |
| 187 | {{{#!td |
| 188 | {{{ |
| 189 | >>> 'Příšerný kůň' |
| 190 | 'P\xc5\x99\xc3\xad\xc5\xa1ern\xc3\xbd k\xc5\xaf\xc5\x88' |
| 191 | }}} |
| 192 | }}} |
| 193 | {{{#!td |
| 194 | {{{ |
| 195 | >>> 'Příšerný kůň' |
| 196 | 'Příšerný kůň' |
| 197 | }}} |
| 198 | }}} |
| 199 | |----------------------- |
| 200 | {{{#!td |
| 201 | Unicode: |
| 202 | }}} |
| 203 | {{{#!td |
| 204 | {{{ |
| 205 | >>> u'Příšerný kůň' |
| 206 | u'P\u0159\xed\u0161ern\xfd k\u016f\u0148' |
| 207 | }}} |
| 208 | }}} |
| 209 | {{{#!td |
| 210 | {{{ |
| 211 | >>> u'Příšerný kůň' |
| 212 | 'Příšerný kůň' |
| 213 | }}} |
| 214 | }}} |
| 215 | |----------------------- |
| 216 | {{{#!td |
| 217 | Bytes: |
| 218 | }}} |
| 219 | {{{#!td |
| 220 | {{{ |
| 221 | >>> b'Příšerný kůň' |
| 222 | 'P\xc5\x99\xc3\xad\xc5\xa1ern\xc3\xbd k\xc5\xaf\xc5\x88' |
| 223 | }}} |
| 224 | }}} |
| 225 | {{{#!td |
| 226 | {{{ |
| 227 | >>> b'Příšerný kůň' |
| 228 | SyntaxError: bytes can only contain ASCII literal characters. |
| 229 | }}} |
| 230 | }}} |
| 231 | |