22 topics
Python help, starting with the last line of the traceback
A Python traceback is read from the bottom up, and almost every student reads it from the top down. The bottom line names the exception and the line that raised it; everything above is the chain of calls that got you there. Students who learn that one habit stop guessing at NameError and TypeError within a week, because the error message was already telling them the answer.
Where students get stuck
IndentationError, but my code looks perfectly lined up
It usually is lined up on screen and still mixed underneath: some lines indented with tab characters and some with spaces. Python treats those as different, so a block that looks aligned is not. Turn on whitespace display in your editor, or set it to insert spaces when you press Tab, then reindent the whole block. If you copied a snippet from a website or a PDF, assume it brought foreign whitespace with it and retype the indentation rather than patching it line by line.
I changed one list and the other list changed too
Writing b = a does not make a second list. It makes a second name pointing at the same list object, so appending through either name changes the one list both names see. To get an independent copy use b = a.copy() or b = a[:]. Careful: that is a shallow copy, so if the list holds other lists, the inner ones are still shared. For nested structures use copy.deepcopy. The same rule explains why passing a list into a function lets the function modify your original.
My function keeps remembering values from the last call
You almost certainly wrote a default argument like def add_item(item, basket=[]). That empty list is created once, when the def line runs, not each time you call the function. Every call that omits the argument shares that same list, so the results pile up. The fix is def add_item(item, basket=None), then inside the function write if basket is None: basket = []. Immutable defaults like 0 or None are safe because nothing can accumulate in them.
Sometimes == works and sometimes I am told to use is
They ask different questions. The == operator asks whether two values are equal; is asks whether they are literally the same object in memory. For numbers, strings and lists you want ==. Use is only with None, True and False, which are singletons. The trap is that small integers and short strings are cached by Python, so 5 is 5 happens to be True and 500 is 500 may be False. Never rely on that. Test values with ==, test identity with is, and check for nothing with x is None.
My loop over range does not reach the last number
range(1, 10) stops at 9. The stop value is excluded, which matches the way slicing works so that range(len(items)) covers exactly the valid indices 0 through len − 1. If you need 1 through 10 inclusive, write range(1, 11). If you find yourself writing range(len(items)) just to index into the list, you probably want for item in items, or enumerate(items) when you need the position and the value together.
What's covered
Python Programming topics you can work through with a tutor, generate practice on, or turn into flashcards and a study plan.
Core language
- Variables, numeric types, and string formatting with f-strings
- Conditionals, while loops, and for loops over sequences
- Functions, parameters, default arguments, and return values
- Scope, globals, and why a function cannot reassign an outer name
- Exceptions, try and except, and raising your own
Data structures in Python
- Lists, indexing, and slicing with negative indices
- Dictionaries, keys, and dict methods
- Tuples, sets, and when immutability helps
- List and dictionary comprehensions
- Sorting with key functions and lambda
Objects and modules
- Classes, __init__, and instance versus class attributes
- Inheritance and method overriding
- Dunder methods: __str__, __repr__, __len__
- Importing modules and writing your own
- Virtual environments and pip
Working with files and data
- Reading and writing text files with the with statement
- CSV and JSON handling
- Regular expressions with the re module
- NumPy arrays and pandas DataFrames for coursework
Assessment skills
- Reading tracebacks and isolating a bug with print statements
- Writing tests with assert and unittest
- Docstrings, comments, and PEP 8 style marks
Python Programming questions
Will it just write the assignment code for me?
No, and you would not want it to, because Python courses mark you on being able to explain your own code in a lab demo. It works the way a lab assistant does: you share your screen, it reads the traceback with you, and it asks what you expected that line to do. You still type the fix.
Can it look at the code on my screen rather than me retyping it?
Yes. Share your screen or hold your laptop up to the camera and it reads the file and the error output as they are. That matters in Python more than in most subjects, because indentation and invisible tab characters are exactly what gets lost when you retype a snippet into a chat box.
I am learning Python for a data or science course, not a programming course. Is that covered?
Yes. Pandas DataFrames, NumPy arrays and plotting come up constantly in lab reports, and the confusions there are their own thing — chained indexing warnings, why a column comparison returns a mask, why a loop over rows is slow. It works through those on the whiteboard with your actual dataset shape.
Which Python version does it assume?
Python 3, and it will flag Python 2 habits like print without brackets if you have been following an old tutorial. If your course pins a specific version or restricts you to the standard library, say so at the start and it stays inside that boundary rather than reaching for a package you are not allowed to install.
Stuck on python programming right now?
Talk it through out loud, share your screen, and watch it worked out step by step on a whiteboard.
Start free — no card