Python
Table of Contents
Getting Started
What is Python
Python Syntax
Variables
Operators
Arithmetic Operators (
+,-,*,/,//,%,**)Bitwise Operators (
&,|,^,>>,<<,~)Assignment Operators (
=,+=,-=,/=,//=etc.)Comparison Operator (
==,!=,>,<,>=,<=)Logical Operators (
and,or,not)Identity Operators (
is,is not)Membership Operators (
in,not in)
Data Types
Numbers (including booleans)
Strings and their methods
Lists and their methods (including list comprehensions)
Tuples
Sets and their methods
Dictionaries
Type Casting
Control Flow
The
ifstatementThe
forstatement (andrange()function)The
whilestatementThe
trystatementsThe
breakstatementThe
continuestatement
Functions
Function Definition (
defandreturnstatements)Scopes of Variables Inside Functions (
globalandnonlocalstatements)Default Argument Values
Keyword Arguments
Arbitrary Argument Lists
Unpacking Argument Lists (
*and**statements)Lambda Expressions (
lambdastatement)Documentation Strings
Function Annotations
Function Decorators
Classes
Class Definition (
classstatement)Class Objects
Instance Objects
Method Objects
Class and Instance Variables
Inheritance
Multiple Inheritance
Modules
Modules (
importstatement)Packages
Errors and Exceptions
Handling Exceptions (
trystatement)Raising Exceptions (
raisestatement)
Files
Reading and Writing (
withstatement)Methods of File Objects
Additions
The
passstatementGenerators (
yieldstatement)
Brief Tour of the Standard Libraries
Serialization (
jsonlibrary)File Wildcards (
globlibrary)String Pattern Matching (
relibrary)Mathematics (
math,random,statisticslibraries)Dates and Times (
datetimelibrary)Data Compression (
zliblibrary)
User input
Terminal input (
inputstatement)
Prerequisites
Installing Python
Make sure that you have Python3 installed on your machine.
You might want to use venv standard Python library to create virtual environments and have Python, pip and all dependent packages to be installed and served from the local project directory to avoid messing with system wide packages and their versions.
Depending on your installation you might have access to Python3 interpreter either by running python or python3. The same goes for pip package manager - it may be accessible either by running pip or pip3.
You may check your Python version by running:
python --versionNote that in this repository whenever you see python it will be assumed that it is Python 3.
Installing dependencies
Install all dependencies that are required for the project by running:
pip install -r requirements.txtTesting the Code
Tests are made using pytest framework.
You may add new tests for yourself by adding files and functions with test_ prefix (i.e. test_topic.py with def test_sub_topic() function inside).
To run all the tests please execute the following command from the project root folder:
pytestTo run specific tests please execute:
pytest ./path/to/the/test_file.pyLinting the Code
Linting is done using pylint and flake8 libraries.
PyLint
To check if the code is written with respect to PEP 8 style guide please run:
pylint ./src/In case if linter will detect error (i.e. missing-docstring) you may want to read more about specific error by running:
pylint --help-msg=missing-docstringFlake8
To check if the code is written with respect to PEP 8 style guide please run:
flake8 ./srcOr if you want to have more detailed output you may run:
flake8 ./src --statistics --show-source --countLast updated
Was this helpful?