Python and My Journey
My daily Python course - a day-by-day learning log.
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
Blaise Pascal invented the first mechanical calculating machine. John Von Neumann: Modern Computer.
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)
Day 3: Programming
Programming is the set of instructions given to a computer to follow using a language it understands. Python uses an interpreter.
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.
Day 5: A Bit More Complex
-
check_circle
isoperator andid()can be used to find the memory address -
check_circle
type()for the variable type -
check_circle
valuefor the value in the variable
Mutable (value can change): list, set, dict. Immutable (value cannot change): int, float, bool, str, tuple.
Day 6: Separators
>> print(1, 2, 3, 4, sep='-') 1-2-3-4 >> print(1, 2, 3, 4, sep='*', end='#') 1*2*3*4#
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
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.
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()