New Playground and Cheatsheet for Learning Python

I’m learning Python and I decided to create a repository where I could put Python script samples with standard Python syntax, structures and statements examples just to be able to quickly recap how to use this or that feature of the language.

Here is what I’ve got.

This is a collection of Python scripts that are split by topics and contain code examples with explanations, different use cases and links to further readings.

It is a playground because you may change or add the code to see how it works and test it out using assertions. It also allows you to lint the code you’ve wrote and check if it fits to Python code style guide. Altogether it might make your learning process to be more interactive and it might help you to keep code quality pretty high from very beginning.

It is a cheatsheet because you may get back to these code examples once you want to recap the syntax of standard Python statements and constructions. Also because the code is full of assertions you’ll be able to see expected functions/statements output right away without launching them.

How to Use The Repo

Each Python script in the repository has the following structure:

“””Lists <— Name of the topic here # @see: https://www.learnpython.org/en/Lists <– Link to further readings goes here Here might go more detailed explanation of the current topic (i.e. general info about Lists). “”” def test_list_type(): “””Explanation of sub-topic goes here. Each file contains test functions that illustrate sub-topics (i.e. lists type, lists methods). “”” # Here is an example of how to build a list. <– Comments here explain the action squares = [1, 4, 9, 16, 25] # Lists can be indexed and sliced. # Indexing returns the item. assert squares[0] == 1 # <– Assertions here illustrate the result. # Slicing returns a new list. assert squares[-3:] == [9, 16, 25] # <– Assertions here illustrate the result.

So normally you might want to do the following:

  • Find the topic you’re want to learn or recap.
  • Read comments and/or documentation that is linked in each script’s docstring (as in example above).
  • Look at code examples and assertions to see usage examples and expected output.
  • Change code or add new assertions to see how things work.
  • Run tests and lint the code to see if it work and is written correctly.

Table of Contents

  1. Getting Started
  2. Operators
  3. Data Types
  4. Control Flow
  5. Functions
  6. Classes
  7. Modules
  8. Errors and Exceptions
  9. Files
  10. Additions
  11. Brief Tour of the Standard Libraries

I hope you find this repository helpful!

August 31, 2018

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of

© HAKIN9 MEDIA SP. Z O.O. SP. K. 2013