Py Pionneering 1

Introduction to Python

Presented by Code Forge® Academy of Programming, a Sparks-Elite® Initiative

About Code Forge® Academy of Programming

Welcome to CodeForge, a global community of students and learners passionate about programming! Our Discord server is dedicated to providing a platform for individuals from around the world to come together and learn various programming languages through simple, efficient, and digitally accessible tutorial classes. Whether you're a beginner or an experienced coder, CodeForge is the perfect place to enhance your skills, share knowledge, and connect with like-minded individuals. Join us today and start forging your coding skills!

Python Introduction Roadmap
Topics

Introduction

What is Python?

Python is a versatile, high-level, general-purpose programming language known for its readability and ease of use, making it a popular choice for beginners and experienced programmers alike.

HISTORY OF PYTHON

Guido van Rossum created Python in the late 1980s as an alternative to traditional programming languages. The first version was released in 1991. He is decorated by the title "The Great Dictator of Life" for his dominance in programming and his supreme authority over Python and depended languages.
Python program structure is similar to the data analysing and control methods used by Guglielmo Markoni in his invention of radio transmitters. Hence it is considered as the predecessor of python syntax.

FEATURES OF PYTHON
  • Easy to Learn:
    Python has a simple syntax and is relatively easy to learn, making it a great language for beginners.
  • High-Level Language:
    Python is a high-level language, meaning it abstracts away many low-level details, allowing developers to focus on the logic of their program.
  • Object-Oriented:
    Python supports object-oriented programming (OOP) concepts like classes, objects, inheritance, and polymorphism.
  • Dynamic Typing:
    Python is dynamically typed, which means you don't need to declare the data type of a variable before using it.
  • Large Standard Library:
    Python has an extensive collection of libraries and modules that make it suitable for various tasks, such as data analysis, web development, and more.
  • Cross-Platform:
    Python can run on multiple operating systems, including Windows, macOS, and Linux.
  • Extensive Community:
    Python has a vast and active community, ensuring there are many resources available for learning and troubleshooting.
  • Rapid Development:
    Python's syntax and nature make it ideal for rapid prototyping and development.
  • Integration:
    Python can easily integrate with other languages and tools, making it a popular choice for scripting and automation.
  • INSTALLING PYTHON...
  • Many PCs and Macs will have python already installed.
  • You can install python directly from python.org site. Installing via this method will automatically install an IDLE platform in your system where you can run your python code effortlessly.
  • Online Compilers
    You can access program in python using several online platform (python compilers). Most of them are free and facilitates google account sign in to save your code.
    In today's interactive workshop, we are using such an online platform called Programiz, where you can try running the coding techniques you will learn here, whenever you like. For convienience.
  • Android/ios applications
    Few notable apps i can suggest are pydroid, pymata, pyrun, etc..
  • VSCode
    It is the most widely used software for pythom programming.
  • To check if you have python installed on a Windows PC, search in the start bar for Python or run the following on the Command Line (cmd.exe):
    C:\Users\Your Name>python --version
  • To check if you have python installed on a Linux or Mac, then on linux open the command line or on Mac open the Terminal and type:
    python --version
  • Once python is installed, you can even run a responsive python IDLE in terminal by entering the following in the terminal:
    python3
  • Significance of Python over other languages
    Levels Of Python knowledge

    Based on the difficulty and experience required for various purposes, python knowledge is catogorized into 6 levels.


  • Python Beginners (Syntax)

    Beginner friendly python, easily understandable code, focuses on syntax , allows programmers to design solutions against basic problems dynamically and mathematically, debugging of code, exception handling, various beginner level modules and libraries.


  • Python Intermediate (OOP)

    Milestone to development field, focuses on Object Oriented Programming, code structures, design structures, design patterns, classes,methods, complex programms, etc..


  • Web Developer (Frameworks)

    Focuses on web frameworks using python language, full stack web developing using Django and microstack web development using flask, back end web development, integration of other web development and designing languages like html, css, js, php, etc..


  • App Developer (Frameworks)

    Designing basic apps using libraries like kivy, tkinter. Designing advamced softwares and applications using python composite languages like Jython, Jedlin, Rust, Ruby, Kanat, Kotlin, Java etc..


  • Analyst (Database)

    Advanced datascience and database management, building firmwares, cybersecurity, firewalls, data automation, data proofreading, etc..


  • Python Expert (Machine Learning)

    Exploring the field of machine Learning, algorithms, deep learning, reinforced learning, API integration, dataset training, language models, working with advanced libraries like pandas, keras, tensorflow, etc. Data processing, Big data, Artificial Intelligence and more..


  • All the six levels of python are available as individual certified courses at Code Forge Academy.

    Python Basics

    Variables, values and constants

    Variables are certain memory locations allotted in the program to save data which are supposed to change over time. values are the data saved into the variables. in certain and situations, the values in the variables are not supposed to change during code execution. this value is called as constants. unlike most other languages, python doesn't have a way to declare a constant. so certain naming conventions are practiced to denote constant values.

  • Using CAPSNAME

  • Using cc_name

  • Uaing camelCase

  • When naming a variable or constant, only include upper and lowercase alphabets, numbers and under scores. no spaces or fullstops. name shouldn't start with a number or underscore. in case of names having spaces, use underscore instead or follow camelCase standard.

  • variable_name="Name"
  • variable_number="30"
  • cc_gravitational_constant=9.814
  • variableName="Name"
  • variableName28="Name of 28th member"
  • Operators
    Control Structures

    They are keywords which are used to run a certain codeblock as long as a specific condition is satisfied.

  • if... elif...else
  • Checks whether the condition is satisfied before running the code. if ... states the initial condition, elif... elif... elif... can be used to define alrenate conditions, if the primary condition is not satisfied, else... definea the action to be taken if none of the conditions are satisfied.

    CODEBLOCK today = "friday"
    if today == "sunday" :
    __ print("Today is a holiday")
    elif today == "saturday" :
    __ print("Today is a weekend")
    else :
    __
  • for loop
  • Checks whether the condition is satisfied before executing the code and loops through it as long as the condition remain satisfied. break and continue are some of the methods used in for loop to terminate and skip the repeating code, even while the condition for the codeblock is satisfied.

    for i in range(5) :
    __print(i)

    here, the variable which pass through incrementation each time the loop repeats, is known as iterator, which controls the condition for the code execution.

  • while loop
  • While loop is similar to for loop in most cases, but the major difference between them is, in for loop the iteration number is known or predictable and the number of times the code is repeated is predefined before executing the code. But in while loop, the number of times the code repeats is unknown and the code repeats as long as the condition is proved to be unsatisfiable.

    i=0
    while i<0 :
    __ print(i)
    i= i+1
    Control Flow or Console Flow
  • print() outputs a value to the console, which can be a string, integer, data stored in a variable, a list, a dataset, etc,.
  • print("Welcome to CodeForge")
    print("32+18")
    a =32/4
    print(a)
  • input("prompt") takes in a user input from keyboard and can be stored in a variable or constant
  • a=input("Enter your name")
    print("Hello \t",a,"\n","Welcome to CodeForge"
    Data Types

    Data types defines in which format the data we store into a variable is saved. Unlike other programming languages, in python, the interpreter and compiler can self distinguish the type of data we store into a variable, to an extent. we can also convert one data type into other in most cases, while it may sometimes alters the data itself. Different datatypes occupy different amount of storage space in bytes.

  • str() - String file - "Hello World!"
  • int() - integer - 1,2,3,....
  • float() - decimal values - 1.1, 2.6, 7.9,....
  • boolean() - state - True or False
  • list() - a collection of similar or different datatypes - ["hello", 2, 3.7, True]
  • Functions

    They are a set of predefined code, saved in a location, which does not execute on its own unless it is called upon in the main program.

    def myFunction ():
    __ a=6
    __ b=7
    __ print(a*b)

    myFunction()
    Libraries

    A Python library is a collection of related modules. It contains bundles of code that can be used repeatedly in different programs. It makes Python Programming simpler and convenient for the programmer. As we don’t need to write the same code again and again for different programs.
    In python, libraries are usually added to our main program by import keyword.



    Lets try out a fun library this time. Open your Code Playground section and try out this code.

    from turtle import *
    for i in range (4):
    __ fd(20) __ lt(90)
    Syntax

    Python syntax is the set of rules that determine the structure and arrangement of code, including keywords, operators, indentation, and punctuation

  • Intendation - number of spaces in each code line of a parent code block
  • Keywords - Reserved words for the functioning of python language
  • Operators - certain symbols used to interact with memory allocation of code, by system.
  • Punctuation - proper usage of double colon when defining control structures, usage of spaces and tabspaces in code blocks, using # and triple quotes to include comments and documentation in your code and functions

  • Object Oriented Programming

    Functions & Methods
  • Functions are set of predefined program, independent of normal code flow, and does not execute on its own unless called by the main program.
    It utalises global and local scopes to define the data used and stored within and it can except data as well as return data from and to between the function code block and main code.
  • Methods are set of instructions contained within a function, which can utalise the data and code within the function, in various independent purposes. It poses a part of the general function , which is exclusive to execute a specific function.
  • Object Oriented Programming

    OOP is an approach of generalizing a model that organizes the raw code, variables and related functions in a code, to the concept of objects, which can interact with each other.
    It focuses on manupulating the objects rather than the logic that controls it. It is a complex approach and is suitable for large scale, complex programming like app development and machine learning.

    Class Objects & Inheritance

    Class - Categorizes datas and functions into groups which share similar logic, properties, and method of implementation.

  • Distinctive Classes - different properties, different methods
  • Dependant Classes - different properties, same methods
  • Distortive Classes - same properties, different methods
  • Degenerative Classes - same properties, same methods, different purpose

  • Error Handling

    Evaluation
  • Eval() method is an underrated method in the modern application of python programming!!
  • Purpose of eval()
  • Why eval() is no longer used ?
  • Execution
  • try: handler attempts to execute a code which may or may not be faulty, and helps to maintain program flow without termination even if errors are present
  • try: handler has a code block which its attempts to execute, if it has errors, the code is exempted and passed to exception handler.
  • Exception
  • except: handler catches the errors from try: block and returns a response, without terminating the programs flow.
  • except: block will handles almost all types of code errors like SyntaxError, NameError, etc
  • try:
    __ for x in range (8):
    __ __ print(y)
    except SyntaxError:
    __ print(" There is a syntax error")
    except :
    __ print("Something went wrong")

    Data Structures

    Data Structure Types
  • List
  • Tuple
  • Set
  • Dictionary
  • Array
  • String
  • Stack (Last In First Out)
  • Queue (First In First Out)
  • Data Structure Methods
  • list.append - adds element to the last
  • list.sort - organize the elements in alphanumerical order.
  • list.insert - adds data to specified location
  • list.remove - remove data from specified location
  • list.reverse - reverses the order of elements.
  • list.index - find index of an element in a list
  • list.count - counts no. of total or target element in the list
  • list.len - find number of elements in a list.
  • dict.keys - find keys of specific value
  • dict.value - find value of specific key
  • dict.items - returns list of items in dict
  • dict.update - updates dict with new key value pair
  • list.pop - removes last element of test.
  • set.add - add unique element to set
  • set.union - returns all elements from both dict
  • set.intersect - returns only common elements between 2 Dictionary
  • Indexing

    Indexing refers to the process of accessing a specific element in a sequence, such as a string or list, using its position or index number. Indexing in Python starts at 0, which means that the first element in a sequence has an index of 0, the second element has an index of 1, and so on.


    File Handling

    Text Files
  • Handles .txt files. Create, edit, read, save, etc.
  • open(location/filename,mode) to open an existing file or create a new file in the target location. Commonly used modes are w-write, r-read, a-append
  • read(filename) to read an opened file, and return the data as a multi-line string file.
  • readlines(filename) to read the contents of a file, line by line.
  • write(filename) to write a file by adding text or string data to it.
  • close(filename) to save the file and finish editing.
  • CSV Data Files

    Usually used in conjunction with data handling modules like numpy, pandas, etc. to tabulate and creating datasets from it.

    JSON Data Files

    Used to parse and process json files, which is similar to the dictionaries in python.

  • importing json library
  • file.jsonload method to parse json files into string format.
  • file.jsondump method to parse string data into json format

  • Algorithms

    Sorting
  • Bubble sort - Bubble Sort: A simple sorting algorithm that repeatedly swaps adjacent elements if they are in the wrong order, passing through the list multiple times until sorted.
  • Merge sort - Merge Sort: A divide-and-conquer sorting algorithm that splits the array into halves, recursively sorts them, and merges the sorted halves back together.
  • Quick sort - Quick Sort: A divide-and-conquer sorting algorithm that selects a pivot, partitions the array into elements less than and greater than the pivot, and recursively sorts the partitions.
  • Searching
  • Binary Search - Binary Search: A fast search method for sorted lists that repeatedly divides the search range in half.
  • Linear Search - Linear Search: A simple search method that checks each element one by one.
  • Indexing Search - Indexing: A technique to speed up searches by creating a reference for quick data lookup.
  • Reg ex - A regular expression is a form of advanced searching that looks for specific patterns, as opposed to certain terms and phrases. With regular expressions, you can use pattern matching to search for particular strings of characters rather than constructing multiple, literal search queries.

  • Designing & Development

    Design Patterns - Analogy Study
  • Singleton - Single occurance or instance for one type of class.
  • Builder - step by step complex construction without common interface. Different product with same process with slight adjustment
  • Decorator - Adding new functionality to existing or predefined objects without altering object structure.
  • Strategy - Family of algorithms or behaviour, categorizing into different units, making them interchangable.
  • Adaptor - Allows objects with incompatible interface or property to collaborate
  • Observer - list all changes to its dependants (observer) of a object (subject) in a subscription mechanism.
  • Command - Turns request into a stand alone object that contains all information about the request.
  • Development Patterns - Analogy Study
  • Waterfall Model - step by step sequential development stages, each phases is passed onto another. aka life cycle model
  • Modular Design - Independent reusable modules, flexiblility, maintainability, work division.
  • Iterative Model - breaking down to smaller manageable cycles, fast process, vulnerable to break down.
  • Recursive model - function calls on itself to solve problems by breakingbdown into smaller , self similar problems.
  • Descriptive methods - Algoritms aware ofbits purpose, structure, solution, etc, rather than specific implementation of code.
  • Terminal model - Terminate Algoritm when feedback is received or goal satisfied , representing all receiver.

  • Package management

    PyPi

    They are open source python libraries made by independented python developers for advanced capabilities. They can be downloaded and imported from pypi.org website.

    PIP

    PIP is an inbuilt package installer of python which can conveniently install external python libraries from a terminal, updates existing ones and organise installed package libraries.

    Git Repository

    Git hub includes several standalone third party Repositories of python packages, developed by independent developers, providing a wide range of functionality and capabilities.

    Conda

    Conda is a cross-platform, language-agnostic package manager and environment management system, used for installing, updating, and managing software packages and their dependencies, particularly for data science and machine learning projects.


    App Testing

    Pytest

    Pytest fixtures provide the contexts for tests by passing in parameter names in test cases; its parametrization eliminates duplicate code for testing multiple sets of input and output; and its rewritten assert statements provide detailed output for causes of failures.

    Pykit or Pyunit

    Pykit aka Pyunit test is a built-in testing framework that provides a set of tools for testing our code’s functionality in a more systematic and organized manner. With pykit framework, we can create test cases, fixtures, and suites to verify if our code behaves as expected. It allows us to write test methods within classes that check different aspects of our code such as input, output, and edge cases. It also supports test discovery making it easy for us to automate test execution across our project.it comes especially handy when testing object oriented programmings.

    Polls
    Code Playground
    Achievement Task