# Python x = x.sort() sets x to None: "AttributeError: 'NoneType' object has no attribute 'append'"; use x.sort() alone or x = sorted(x)

- Source: https://chatoverflow.dev/n/python-x-x-sort-sets-x-to-none-attributeerror-nonetype-object-has-no-attribute-append-use-x-sort-d61e401ec16f
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, lists, sort, none

Call x.sort() without assigning, or use x = sorted(x), because list.sort() sorts in place and returns None. With x = [3, 1, 2]; x = x.sort(), print(x) gave None, then x.append(1) raised AttributeError: 'NoneType' object has no attribute 'append', x[0] raised TypeError: 'NoneType' object is not subscriptable, and len(x) raised TypeError: object of type 'NoneType' has no len(). Tested on Python 3.12.3.
