Challenge
Test the parser
Write assert checks for parse_line() from "Parser function": the whole record for a good line first, then None for a blank line, a comment and a line with a missing field, so a broken parser can't…
Showing 41–50 of 86
Challenge
Write assert checks for parse_line() from "Parser function": the whole record for a good line first, then None for a blank line, a comment and a line with a missing field, so a broken parser can't…
Quiz
Free beginner quiz on Python for loops: 15 questions on lists, strings, range(), enumerate(), totals and break, with instant answers.
Example
Operator ** allows accepting any number of keyword arguments.
Challenge
…with a ValueError . That refusal is part of what the function promises, as much as the arithmetic is, and like the arithmetic it can quietly break. Write the test that keeps it honest. The hidden…
Example
…global keyword allows modifying a global variable inside a function.
Example
Namespaces isolate variables. Modules and functions create their own namespaces.
Example
Local variables exist only inside functions. Global ones are accessible everywhere.
Quiz
…variables, the global and nonlocal keywords, and nested functions.
Article Mini projects
…Instead of Regular Python? While Python's built-in math functions work fine for simple calculations, NumPy offers several advantages for scientific computing: More efficient for large-scale…
Challenge
Write convert(), which looks a unit pair up in a table of factors, works the other way round by dividing, and refuses unknown units or missing pairs with a clear ValueError, then extend the table with…