# Basic Python Programming This is a fairly intense two day workshop on learning basic Python programming. The course is completely hands-on and requires each student to have access to a computer with the necessary software installed and with internet access. The workshop is designed to be taken with our online testing platform called [yaksh](http://yaksh.fossee.in). After every hands-on lecture, we have a practice session where students are expected to solve the given problem on our online platform. The solutions to each problem will be shown and students will proceed to the next problem. Close to 60 exercises will be solved by the students over the course of this workshop. Students will also need to take a programming test to be assessed and receive certificates. The course only covers basic Python programming. See the outline of the course below to see what is covered. ## Intended audience and pre-requisites This course requires that students have completed our "Introductory Scientific Computing with Python" course and passed it. This course is designed to be taken by folks who do not have any significant programming experience. The students should be comfortable using a computer and editing text files. ## Software and hardware requirements A laptop or reasonably configured desktop is recommended since this will be a hands-on session. Please install Python 3.x (or 2.7.x if 3.x is not available) for this course. On Linux, Windows and Mac OS X it is easiest to install Python and many other useful packages by installing Anaconda. Download the Anaconda Python distribution for your OS and architecture from here: https://www.anaconda.com/products/individual. The instructions to install are available here https://docs.anaconda.com/anaconda/install/ You can use Anaconda or Conda along with the Spyder editor or the VSCode editor. On many Linux distributions, Python is already available. We suggest that you install Python 3.x and are comfortable with any text editor. Editors that integrate with Python would be better. ## Outline of the course - Python Basics: - Basic datatypes: numbers, booleans, and strings - Basic operators: arithmetic, string operators, and string methods. - Relational and logical operators. - `assert` statements and built-ins. - Simple input and output with `input` and `print`. - Simple Exercises. - Practice exercises for the basics. - Basic control flow in Python: - Conditional flow with `if/elif/else`. - The ternary operators. - Looping with `while`. - Solving a simple problem. - Looping with `for` and `range`. - Using `break`, `continue`, and `pass`. - Exercises - Practice exercises for control flow. - Core data structures in Python: - Lists - Tuples - Dictionaries - Sets - Some exercises. - Practice exercises for the core data structures. - Writing functions. - Simple functions taking no arguments, returning `None`. - Functions taking arguments and returning values. - Docstrings. - Returning multiple values. - Default arguments. - Keyword arguments. - Variable scope when defining functions. - Mutable vs immutable arguments. - Example functions to read for practice. - Nested functions. - Returning functions. - Practice exercises for functions. - Python modules. - Creating modules - Importing modules. - `sys.path`, `PYTHONPATH` - Running modules as scripts - The use of `__name__`. - Reading and writing files. - Reading files. - Writing files, using `.write` and using `print` - Example: parsing data from a file. - Python exceptions: - Standard exception examples. - Catching exceptions with `try/except` - Catching multiple exceptions. - Cleanup with `finally` - Raising one's own exceptions. - Practice exercises for files and exceptions.