The aim of this course is to allow scientists, engineers and others who have programming experience become confident in reading, writing and working with code in Python.
We'll start with syntax, data types and flow control and finish with working with files, threads and processes.
Each section will be accompanied with slides, sample code, a lab and solutions.
As a live course, we can go deeper on topics that are of interest, whether or not they are on the syllabus or not.
- 09.00-10.30 - Session 1
- 10.30-11.00 - Break
- 11.00-12.30 - Session 2
- 12.30-13.30 - Lunch
- 13.30-15.15 - Session 3
- What is Python and where is it used?
- What are common Python libraries?
- Exploring the Python execution model
- Running programs
- Isolating Python environments
Lab 1: Get setup with your environment. Use Pycharm, VSCode or any other editor that you feel comfortable with.
- Variables and types
- Converting types
- Strings, Numbers and None
- Arithmetic and assignment
Lab 2: Make things interactive. Capture user input to variables and use it.
- If, else, eli
- Comparison and logical
- If expressions (tenaries)
- While
- For
- Break, Continue, Else
Lab 3: Iteration and control
- Python Collection types
- Tuples
- Lists
- Collection constructor
- Check for membership and iterations
Lab 4: Use containers to capture your values
- Sets
- FrozenSets
- Dictionaries
- List comprehensions
Lab 5: Use dictionaries
- Defining functions
- Default parameters
- Named parameters
- Returning values
- Returning multiple values
- The sum function
Lab 6: Make your code more functional
- Docstrings and reStructuredText
- Arbitrary parameter lists
- Positional and Keyword parameters
- Local and Global variables
- Lambda functions
- Higher order functions - filter and map
Lab 7: Higher order functions
- Everything is an object
- Class terminology
- Defining and instantiating a class
- Printing objects
- Defining behaviour
Lab 8: Classes and object oriented programming
- Errors and exceptions
- Exception handling
- try-except blcoks
- Raising an Exception
- Defining new exceptions
Lab 9: Handling failure
- Python modules
- Importing modules
- Module properties
- The
mainmodules - Importing non-local modules
Lab 10: Modularise your code to make it more reusable
- Testing frameworks
- Pytest
- Writing tests
- Assertions
- Fixtures
- Parameterising tests
- Testing for exceptions
Lab 11: Leveraging automated testing to trust your code more
- Duck typing
- Impliciat contracts
- Protocols
- Iterables and Iterator protocol
Lab 12: Know how to leverage built-in Python features
- Data generators
- Generators and Generator functions
- Generator with a for loop
- yield
Lab 13: Experiment with generators and decide if you like them.
- String and regular expressiongs
- Copying
- Operators as methods
Lab 14: Compare, contrast and regular expressions
- Obtaining a file reference
- File access modes
- Reading and writing
- Context handlers
- Renaming, deleting and managing files
Lab 15: Work with files
- What is a thread?
- What are the thread states in Python?
- The Thread Class
- Creating a Thread
- Passing arguments to a thread
- Multiple threads
- Timers
Lab 16: Optimise your code with threads
- The multiprocessing library
- The process class
- Working with the Process class
- Alternative ways to run a process
- Using a pool
Lab 17: Optimise your code with processes
Google Drive (CERN Python programming) https://drive.google.com/drive/folders/1Ivr3lT3lIq-1RXcvpDbh91NXcVBYhFuJ?usp=share_link