
This course includes our updated coding exercises so you can practice your skills as you learn.
See a demo
Introduction to the course: contains important information!
Install Python and set up a virtual environment, then learn basic Python syntax—variables and flow control—so you can write scripts to automate tasks and reformat data.
Set up a Python virtual environment to ensure you run the correct Python and pip versions, then activate it in a terminal in Visual Studio Code or PowerShell on Windows.
Create and run a Python hello world program in Visual Studio Code, using the .py extension and print function, and learn indentation with four spaces.
Learn how Python variables are declared by naming and assigning values with no type. Referencing undefined variables triggers underlining, while strings use quotes, integers are unbounded, constants appear uppercase.
Explore built-in functions in Python, including input, string concatenation, and freestanding functions, with a practical demo of reading names and printing greetings.
Explore Python's if statements and the ternary operator, using boolean operators and not and or, with examples of raining, temperature, and simple conditions. Learn indentation, elif, and else, plus comments.
Explore Python for loops, iterables, and the range function to iterate sequences with start, end exclusive, and optional steps, and print multiple values.
Explore while loops in Python, including the else clause, incrementing with plus equals, and using break and continue to control execution.
Explore Python's casting and arithmetic operators, converting between int, float, and str; compare / and // division, modulo, and exponent, using input and string concatenation as examples.
Explore string comparisons in Python, learning the equals operator, case-insensitive checks with lower, and lexicographical ordering using Unicode values. Use ord to get codes and char to convert codes.
Explore Python's match statement as the switch equivalent since Python 3.10, using cases, a default underscore, no breaks, and alternatives with a vertical bar.
Discover how Python supports freestanding functions and how they compare to class methods, while mastering various argument passing techniques; explore how Kotlin inherits Python features.
Learn to define Python functions with def, name them with underscores, call them, return values, and use positional and default arguments; note no overloading and identity from name and module.
Learn how Python supports keyword arguments and positional arguments to call functions, name parameters like width and height, use optional length with a default, and mix orders for flexible calls.
Learn how to use a variable-length argument list in Python with an asterisk prefix, treating args as a tuple you can iterate over and index.
Explore variable-length keyword arguments in Python with **kwargs, treat them as a dict, access and iterate named parameters safely.
Explore how Python returns multiple values with tuples, unpacking them into separate variables, and mixing types, highlighting differences from Java.
Compare Python's built-in container types with Java collections, showing how Python's lack of strong typing makes containers simpler, and explore tuples and powerful list comprehensions for practical code.
Explore Python tuples, the immutable container type, and learn packing and unpacking values, indexing, and star unpacking that collects remaining items into a list.
Learn how Python slicing creates subparts of tuples (and later strings and lists) using start, end, and step, including negative indices, with end-exclusive ranges and default values.
Explore tuple functions and methods in Python using len, max, min, count, and index; see their application to strings and lists and how errors occur with missing indices.
Demonstrate tuple operators in Python, including adding, multiplying, and repeating tuples, and using plus equals to create new tuples, while id reveals immutability.
Learn multiple Python list removal techniques, including removal by value, using pop by index, slicing, the del keyword, and list.clear, plus how pop returns the removed item.
Explore how Python list comprehensions build lists from ranges and existing lists, including squaring numbers and copying lists like animals. Learn how they differ from tuples and how generators arise.
Learn how to apply conditions in Python list comprehensions to filter and transform data. The lecture covers using if filters and if-else expressions to modify words by length, including uppercasing.
Explore Python sets, which store unique items with no order, created by curly brackets, the set constructor, or set comprehensions, and use in, add, update, remove, and discard.
Explore Python set functions such as union, intersection, difference, and symmetric difference. Learn how superset works and how the minus operator does the same as difference.
Explore Python dictionaries, the map-like key-value containers, learn to create, access, update, iterate, and delete entries, and see how they compare to Java maps.
Explore removing items from dictionaries using the del operator, pop, and pop item; compare clear versus setting to an empty dictionary, with practical tips on efficiency.
Explore how dictionary views like keys, values, and items offer dynamically updating containers that reflect changes to the dictionary.
Explore Python's defaultdict from collections, learn how it supplies a default value for missing keys (empty string for strings) and prevents a traceback.
Explore how hashing works in Python, using the hash function to determine hashability, and learn why lists are unhashable while tuples are hashable only when their contents are immutable.
Learn to write Python regular expressions with the verbose flag to include comments, build multi-line patterns, capture IDs with groups, and match tag content and end tags.
Explore how to use Python's re.search to find patterns in text, including capture groups and handling multi-line strings with the DOTALL flag.
Explore Python's regular expression module findall to retrieve all matches in text, using capture groups, literal dots, and multi-line strings, and compare with match and search behavior.
Explore the multi-line flag to match the start and end of each line in a regular expression, using dot star, dot all, and the multi-line option for per-line matches.
Explore compiling regular expressions with re.compile and substituting text with re.sub in strings. Flags are embedded in the compiled pattern, so ignore case works only when included during compile.
Learn to raise and handle exceptions in Python, using the raise keyword, the base Exception class, and creating custom exceptions with inheritance; catch and print them with try and except.
Discover how to use Python assertions, including the assert keyword to enforce conditions, trigger assertion errors with custom messages, and optionally catch them with try-except, mirroring Java behavior.
Explore object oriented programming in Python, covering classes, objects, inheritance, overriding methods, multiple inheritance, and operator overloading to add functionality to your classes by implementing operators beyond Java.
Explore Python constructors by defining __init__ and using self to create attributes. Learn how to pass data, manage arguments, and understand protected and private naming with underscores and dunder methods.
Learn how to convert Python objects to strings by implementing the __str__ method and using str(obj) to obtain the string representation.
Explain Python's __repr__ returns a machine-readable string that can recreate objects, using a format string and repr, and caution about using eval to run such strings.
Explore Python inheritance by extending a person class with an employee subclass and defining go on holiday and eating methods. Constructors are inherited in Python.
Override methods in Python subclasses to customize behavior; extend an animal with a cat that defines meow, and call speak, noting you can't overload by types or numbers.
Establish python class attributes, the equivalent of java's static fields, outside of methods and access them via the class name to track shared state across instances.
Explore multiple inheritance in Python by combining a car class with an alarm class and using a mixin to bolt on functionality, while handling self arguments and is-a relationships.
Explore how Python resolves methods in inheritance using the method resolution order (MRO). See how C from A and B selects run via C.MRO, illustrating the diamond problem.
Develop a Python class word that overloads the add operator to concatenate text, enabling w1 plus w2 to yield a new word with combined text.
Discover printing the value and importing parts of modules in Python with from module import value and from module import value1, value2, demonstrated in main.py and mymodule.py.
Learn how Python initializes a package by adding a __init__.py in the package folder, controlling imports with __all__, and preferring explicit imports like from stuff import greetings over import star.
Create package attributes by placing import statements inside packages and using __init__.py to expose subpackages. Build convenient access to nested modules via from . import mymodule and attribute chaining.
Install Python packages using pip, ensuring the correct pip version via a virtual environment, then manage packages with pip install, pip list, and pip uninstall. Try installing NumPy.
Explore passing functions to functions in Python, where Python's lack of strong typing keeps it simple. A run function accepts a function like greet and executes it to produce hello.
Explore how the Python map function transforms iterables by applying a one-argument function, such as str.lower, to each item and producing a lowercase list of animals.
Learn how to use Python lambda expressions in the Python for Java developers course to map strings and extract the first three characters, with optional lowercasing of the results.
Explore Python's sorted built-in function to sort iterable containers. Use the reverse option and a custom key with a lambda to sort by length.
Learn how to filter iterable containers in Python using the built-in filter function, with a lambda condition to keep items containing the letter e, demonstrated on a fruit list.
Learn how generators in Python differ from list, set, and dictionary comprehensions, why they produce items on demand, and how to iterate and cast to lists.
Learn to read text files in Python by opening test.txt in the same directory as main.py, using readlines or read, and optionally removing newline characters with splitlines or strip.
Explore how Python's with statement ensures automatic resource closure by implementing __enter__ and __exit__ in your classes, mirroring Java's try-with-resources. Use with open('test.txt') as file to read lines.
Learn to write text files in Python using with open in text mode and the write method to create temp.txt. Run python main.py to confirm the file appears.
Learn to work with binary data in Python, create bytes and bytearray objects, and write them to a file, noting ASCII characters and the immutable vs mutable difference.
Learn to read binary files in python by opening binary files like test1.bin, reading with file.read(n) for five bytes, and inspecting the bytes to see ascii values via indexing.
This course will help you to learn to program in Python by leveraging the skills you already have in Java, or another high-level object-oriented programming language.
I won't waste your time explaining things you already know, like what functions are, or exceptions or classes. Instead, we'll dive right into how to make use of the concepts you already understand in another language, in Python.
We'll start with the most important syntax first, so that after the first section or two you'll already be able to write Python scripts. Then we'll cover how to work with classes, containers, regular expressions and files in Python, and more.
You'll also learn how to use Numpy for numerical computing (less complicated than it sounds!) and how to use Pandas as a virtual spreadsheet. In the final section we'll cover how to draw charts so you can visualise your data, and how to use a simple artificial neural network to make predictions based on your data.
The courses includes suggested exercises and quizzes to help you check your progress. With a little practice, you can quickly learn to make use of Python for automating routine tasks, processing text data, working with numerical data, or whatever you need to do.
If you already have some programming knowledge and don't want to sit through explanations of basic concepts, but do want to learn to use Python alongside your existing programming skills, this course is for you.