by Suf | Jul 19, 2022 | Programming, Python, Tips
This error occurs if you try to call randint() method on an integer. You can solve this error by not naming an object random, which will override the reserved name for the built-in module random. For example, import random my_int = 10 random_int = random.randint(1,10)...
by Suf | Jul 18, 2022 | Programming, Python, Tips
This error occurs when you try to call the remove() method on a string to remove one or more characters. You can solve the error by calling the replace() method on the string or by calling the remove() method on a string. For example, my_str = ‘fruits’...
by Suf | Jul 18, 2022 | Programming, Python, Tips
This error occurs when you try to call the trim() method on a string to remove whitespace. You can solve the error by using the strip() method to remove leading and trailing whitespace from the string. For example, my_str = ‘ Python ‘ clean_str =...
by Suf | Jul 18, 2022 | Programming, Python, Tips
This error occurs when you try to call len() on a list object. len() is a built-in function, which returns the length of an iterable. You can solve this error by passing the list to the len() function to get the list. For example, my_lst = [2, 4, 6, 8, 10] length =...
by Suf | Jul 16, 2022 | Programming, Python, Tips
This error occurs if you try to call the sort() method on an integer as if it were a list. You can solve this error by ensuring you do not assign an integer to a variable name for an existing list that you want to sort. For example, my_int = 14 my_list = [17, 222, 23,...
by Suf | Jul 15, 2022 | Programming, Python, Tips
This error occurs when you pass an incorrect mode to an open() function call. If you want to open a file for both reading and writing you can use r+ only if the file exists. You can use w+ if the file does not exist or if you do not mind overriding an existing file....