code
school Learning Journal

Python and My Journey

My daily Python course - a day-by-day learning log.

psychology

Day 1: Computational Thinking

Computational thinking involves four key concepts:

  • check_circle Decomposition: Breaking down bigger problems to smaller ones
  • check_circle Pattern Recognition: Finding similar problems and applying already solved questions
  • check_circle Abstraction: Identify the root cause and remove other factors
  • check_circle Algorithm Design: We come out with step by step processes to solve the problem. Pseudo code, Flowcharts
info

Blaise Pascal invented the first mechanical calculating machine. John Von Neumann: Modern Computer.

layers

Day 2: Software Anatomy

  • devices UI (User Interface) - Client/Front-end: Contains the Presentation logic (C, C++, HTML, CSS, JavaScript, Node, etc. If it is a mobile app, technologies such as Ionic, Swift, or Kotlin)
  • storage Database: Stores the data (MySQL)
  • dns Server - Backend: The end (PHP, Ruby, Python, and Go)
terminal

Day 3: Programming

Programming is the set of instructions given to a computer to follow using a language it understands. Python uses an interpreter.

calculate

Day 4: Python Basics

Basic operators and order of precedence:

+   Addition
-   Subtraction
*   Multiplication
/   Division
**  Power
%   Remainder

Order of Precedence: Parenthesis, Power, Multiplication, Addition, Left to Right.

memory

Day 5: A Bit More Complex

  • check_circle is operator and id() can be used to find the memory address
  • check_circle type() for the variable type
  • check_circle value for the value in the variable
info

Mutable (value can change): list, set, dict. Immutable (value cannot change): int, float, bool, str, tuple.

tune

Day 6: Separators

>> print(1, 2, 3, 4, sep='-')
1-2-3-4

>> print(1, 2, 3, 4, sep='*', end='#')
1*2*3*4#
build

Day 7: Functions

A function is a block of organized, reusable code used for a single related action. Functions give better modularity and a high degree of code reuse.

  • check_circle Built-in: print(), min(), max()
  • check_circle User-defined: Whatever you want
def functionname():
    functionstuff
    return  # indentation required

Docstrings

Docstrings provide detailed documentation for a function. They can describe the function's purpose, arguments, return values and more. A docstring is added as the first statement in the body of a Python function, within triple-quotes """docstring""".

def calc(quantity, price):
    """Returns the product of quantity and price"""
    return quantity * price

print(calc.__doc__)
# Returns the product of quantity and price
bug_report

Day 8: Errors

  • error Syntax Errors
  • warning Runtime Errors: NameError, IndexError, TypeError, ValueError, ImportError
  • help Logical Errors

Try/Except: Used to handle errors gracefully, similar to error handling in other languages.

folder_open

Day 9: Files

Open files using the open() function. This gives a file handle which provides file operations like read and write.

fhandle = open("myfile.txt", "r")
# We can use the read() function too
content = fhandle.read()