Hey Readers, I have recently stumbled upon a lot of Python Oddity Snippets on the web. With this post, I hope to share some of them with you all.

``````  _   _   _   _   _   _     _   _   _   _   _   _
/ \ / \ / \ / \ / \ / \   / \ / \ / \ / \ / \ / \
( p | y | t | h | o | n ) ( o | d | d | i | t | y )
\_/ \_/ \_/ \_/ \_/ \_/   \_/ \_/ \_/ \_/ \_/ \_/
``````

### Python Loop Oddity

``````>>> x = {'a': 1, 'b': 2}
>>> y = {}
>>> for k, y[k] in x.items(): pass
...
>>> y
{'a': 1, 'b': 2}
``````

### Python Boolean Oddity

``````>>> "hello" + True
TypeError: Can't convert 'bool' object to str implicitly
>>> "hello" * True
'hello'
``````

### Python String Oddity

``````>>> "⅐ↁⅣⅧↂⅪ".isnumeric()
True
>>> "ⅬⅭⅮ⅟Ⅿ³₉ↀ".isnumeric()
True
>>> "-3".isnumeric()
False
``````

### Python Addition Oddity

``````>>> a = [1,2,3]
>>> b = {'a': 'b', 'c': 'd'}
>>> a += b
>>> a
[1, 2, 3, 'a', 'c']
``````

### Python Hashing Oddity

``````Functions are valid dict keys!
>>> def greet(): return a
>>> d = {greet: 4}
>>> d[greet]
4
``````

### Python String Operation Oddity

``````>>> abc = 'a\nb\n'
>>> abc.split('\n')
['a', 'b', '']
>>> abc.splitlines()
['a', 'b']
``````

### CPython Oddity

``````>>> x = 4
>>> y = 4
>>> x is y
True
>>> x = 999
>>> y = 999
>>> x is y
False
``````

### Python Syntax Oddity

``````Slashes: you can't end rawstrings with just 1 😦
>>> r'\\'
'\\\\'
>>> r'\'
SyntaxError
``````

### Python Array Oddity

``````>>> a = [1, 0]
>>> a, a[a] = a[a], a
>>> a
[1, 0]
>>> a[a], a = a, a[a]
>>> a
[0, 1]
``````

### Python Instance Oddity

``````>>> isinstance(type, object), isinstance(object, type), isinstance(type, type)
(True, True, True)
``````

Feel Free To Let Us Know More If you Stumble Across Interesting Ones! Thanks for Reading :)