GoConqr has a new look! Let us know what you think.

Mind map

Programming Concepts

Adrien Gallet English

Programming Concepts

Map content

Programming Concepts

  1. Programming Overview

    • Programming is the act of using computer code to communicate with computers. In a nutshell, it's the process of speaking the language of computers.
    • Classification of programming languages
      • This is useless to know for beginners, but as people learn more about programming, it's nice to appreciate the differences between these meanings.
      • Classification parameters
        • Imperative vs. Declarative
        • High-level vs. Low-level
        • Interpreted vs. Compiled
      • Classification groups
        • System languages
          • Examples
            • C++
            • C
            • Assembler
          • Attributes
            • Low-level
            • Used when speed is critical
            • Difficult to master
            • Used when building operating systems, hardware drivers, etc.
        • Architectural languages
          • Examples
            • Java
            • C#
          • Attributes
            • Mid-level
            • Used when building frameworks that will support application development
            • Used to make application development quicker
        • Application languages
          • Examples
            • PHP
            • Ruby
            • Perl
            • Python
          • Attributes
            • High-level
            • Very-fast development
            • Easy to apply
  2. Focused for Python

  3. START HERE

    • Purpose: The aim of this mind-map is to track my progress of learning python. My main learning resource was the Codeacademy course on Python 3, yet I am strongly benefiting from past programming experience.
    • Application: One reason why I am keeping track of this is is to show how the learning process can be broken down into individual concepts. Whilst I think that it is useless to teach these concepts directly from the standpoint of a student, it will inform any teacher perhaps how to structure a course, and what concepts one should cover in tutorial and example based questions.
    • Finally, programming is nothing else but a language. Whilst we are focusing on Python here, one should remembered that it is far more important to understand the concepts used in Python, than the language itself. This is an important ceveat that people only tend to understand once they've learned multiple programming languages, but it's useful to keep that in mind whilst breaking down python.
  4. Key Concepts

    • 1. Programs and Syntax
      • Program: A text file (.txt) which contains the code to talk to the computer.
      • Syntax: The "grammar" of a programming language. Learning this requires repetition so that it becomes instinctive. Consider this: you can probably speak English well, without consciously knowing all grammatical rules. Syntax is exactly the same thing.
      • Comments
        • Comments are piece of code written in the program that are ignored by the computer.
          • # This would be a comment in python
        • Comments are used to:
          • Explain the code
          • Help others understand it faster
          • Ignore a line in code
      • print()
    • 2. Variables
      • Data Types
        • Data Type: A catagory of data
        • Numbers
          • Concept of calculations using operators
        • Strings
          • Concept of concatenation
        • Booleans
          • True
          • False
      • Variable: a way to save data within a program using a specific name
      • Why use variables?
        • Storability
        • Re-usability
        • Change ability
      • How to use variables?
        • 1. Declaration
        • 2. Assignment
        • some_number = 2
          • "some_number" is the variable name
          • "2" is the value of the variable "some_number
    • 3. Operators
      • Arithmetic operators
        • +
        • -
        • *
        • /
        • **
        • %
        • +=
        • -=
      • Comparison/Relational operators
        • <
        • >
        • ==
        • !=
        • <=
        • >=
      • Operators: Symbols that represent an operation that allows us to process data
      • Logical / Boolean operators
        • AND
        • OR
        • NOT
    • 5. Control Flow
      • Control flow: the order in which code is executed. Control structures alter the order of operations in a program.
      • Control Structures
        • Conditionals
          • If statements
            • If else
            • if, elif
          • Switch statements
        • Loops
          • For loops
          • While loops
          • Important concepts
            • Nested loops
            • List comprehensions
        • Exceptions
          • try except statements
    • 4. Functions
      • Function: a sequence of instructions that performs a specific task, packaged as a unit
      • How to use functions
        • 1. Define function
          • Function name
          • Inputs
            • Known as parameters
          • Outputs
            • Known as return
              • Default return is None
              • A return can provide mutiple values, seperated by commas.
                • These need to be unpacked as a tuple when the return is retrieved.
          • Instructions
            • This is the series of expressions which the function needs to execute
          • Scope
        • 2. Call the function
          • "Calling a function" is the process of actually using the function. When we call a function, we use the "function name", write the "parameters" and assign the "return" so some kind of variable.
      • Basic functions
        • print()
      • Function arguments
        • Some definitions
          • Parameter
            • A variable within the definition of a function signature (not in the body, but within the signature, that is an important distinction)
          • Argument
            • A value being passed into a function call
          • Function definition
            • Begins with the keyword def, and includes the entire indented block of code that follows
          • Function call
            • Places where a function is invoked, and needs to come AFTER the function definition
        • None
          • Assigned to a variable if we do not know that value yet
          • Unique
          • Immutable
          • False within conditions
        • Default arguments
          • When default arguments are provided, then they no longer need to be specified during the function call
        • Keyword vs Positional Arguments
          • Positional arguments
            • Arguments that are identified based in the order in which they are forwarded by the function call
          • Keyword arguments
            • Keyword arguments (requires default argument) that are identified by the parameter variable of the default argument
        • Mutable default arguments
          • Mutable default arguments get re-used and not deleted when the function is used several times
          • Mutable objects should be assigned None as a default value, and within the function itself, they should be checked if they contain data or not.
        • Argument unpacking
          • When we don't know how many arguments a function will take, we can use argument unpacking.
          • Positional argument unpacking
            • Syntax: def function_name(*args)
            • When function is called, the list of arguments will be combined into a tuple.
            • Within the function, the args can be treated like a tuple, and iterated like a tuple.
          • Keyword argument unpacking
            • Syntax: def function_name(**kwargs):
            • kwargs is a dictionary, and use .get(kwargs, "key", default_value) to check if a key exists.
            • When the function is called, we need to simply specify different keyword arguments, seperated by commas.
          • Order of arguments
            • 1. Named positional parameters
            • 2. Unpacked positional paramters * args
            • 3. Named keyword parameters
            • 4. Unpacked keyword parameters **kwargs
        • Containers
          • Within a functio call, we may want to submit a list or a dictionary containing the arguments. These are called containers.
            • Use function_call(*list_args) or functio_call(**dictionary_args) to tell python to treat the individual items as arguments.
      • Decorators
        • More complex, yet allows functions to be combined.
    • 5. Data Structures
      • Lists
        • How to use lists.
          • 1. Declaration
            • Empty lists
            • my_list = [2, 5, 7, 9, 10]
          • 2. Accessing lists
            • print(my_list[0])
          • Important concepts
            • Index
              • Negative indices
            • Slicing
              • start:end:stride method
        • Functions and methods
          • .append()
          • .index()
          • range()
          • len()
          • .count()
          • .sort()
      • Data structures are like containers of data, and each data structure has different properties as to how they hold data
      • Tuples
        • These are immutable lists essentially, with very similar properties as lists.
      • Strings
        • Concatenation of strings
          • use of + operator
        • Accessing string values
          • identical to lists my_string[2]
        • Escape characters
          • \"
          • \n
          • \t
        • Iterations through strings
          • Use of for and while loops
        • Conditoinal statements
          • letter in word
          • word in words
        • String methods
          • Formatting methods
            • .upper()
            • .lower()
            • .title()
          • .split()
          • .join()
          • .replace()
          • .find()
          • .format()
      • Dictionaries
        • Dictionary: an un-ordered set of key:value pairs, which is mutable
        • Definition
          • Defined using curly brackets with each key:value pair defined using a colon, and seperated by a comma
            • Example:
              • my_dict = {"name": "John", "last_name": "Smith", "age": 30}
          • Features
            • Keys
              • Keys can be of any immutable type
                • Also known as hashability
              • Need to be unique, otherwise key simply gets over-written
            • Values
              • Values can be of any type, and can even be data structures
        • Dictionaries allow us to map data to each other, and allows us to easily retrieve the value of something
        • Manipulating dictionaries
          • Adding entries
            • new_dict["key"] = value
            • new_dict.update({"key1": value, "key2: value})
              • Arguments needs to be a dictionary
            • Dictionary comprehension
              • new_dictionary = {key:value for key, value in zip(names,heights)}
                • Uses multiple concepts, from for loop, tuple unpacking, zip function and list comprehension
          • Checking keys
            • if key in new_dictionary
            • try: dictionary["dict"] except KeyError: print("Key Error!")
            • .get(key_name, default_value)
              • returns value if key exists, return None if key does not exist or default_value if specified
              • If not assigned to anything, then .get() returns True of False
          • Deleting keys
            • .pop(key_name, default_value)
              • returns value if it exists
              • returns KeyError if not, or default value if specified
          • Accessing keys, values and key:value pairs
            • list(new_dict) will return a list of keys
            • To iterate through keys, values and key, values pairs, we use:
              • .keys()
              • .values()
              • .items()
                • this needs to be unpacked into key, value (since it returns a tuple)
        • Special features
          • Empty dictionary return False
    • 6. Modules (Libraries)
      • Modules: also known as libraries, these are additional files one can "import" into the program in order to use previously defined functions and classes. This is what will add a lot of functionality to programs, and where the real power of Python lies.
      • Basic syntax
        • from module_name import object_name as local_name
        • from module_name
        • from module_name import object_name
      • Well known modules that are really useful
        • datetime
        • random
        • matplotlib
    • 7. Classes
      • Classes: these are templates for data types, and describes the kind of information it hold, and how it will interact with its data
      • Syntax
        • class ClassName():
        • The first letter of a class name is normaly capitalised (convention)
      • Object orientated programming
        • 1. Class definition
          • This is the process of actually defning that class
          • class ClassName():
        • 2. Class instantiation
          • The instantiated class must be assigned to a variable. That variable is called an OBJECT.
          • An object is an instance of a class.
            • We can use the type() method to find out what instance of a class the object is of. Tyoe always returns two things:
              • Namespace
                • __main__
                  • If the class was defined within the currently running script
                • module_name from where the object was imported from
              • Class Name
                • This would simply be the name of the class as it was defined
        • Features
          • Class variables
            • Variables which would be the same for every instance of that class, and shared accross all instances of that class
            • Definition: occurs within the class definition
            • Call: using the object.variable syntax, the variable can be called
          • Methods
            • Methods are functions of classes, which can be called upon using the object.function_name() syntax.
            • Definition
              • When defined, methods need to include the self parameter. They can however hold more arguments.
                • However, when calling the function, the self argument does not need to be called since it is implied implicitly
                • When using a class variable within a method definition, we need to use the self.variable_name syntax
            • Dunder Methods
              • Double UNDERlined mthods (called dunder methods) are special methods invoked when certain operations in relation to the object are made
              • __init__(self)
                • Known as a constructor method
                • Invoked when an object is created, used to initialise certain instance variables
              • __repr__(self)
                • The string representation, when the object is printed without any . dot methods
                • Must return a string
          • Instance variables
            • These are defined once the object is created, or within the constructor method
            • They are unique to that instance of the variable
          • Attribute Functions
            • Attribute: these are variables and other special properties of an object
            • Checking attributes
              • dir()
                • returns a list, when the input argument is the object, of all of that object's attributes
              • getattr(object_name, "attribute", default_value)
                • Default value is returned if attribute does not exist
              • hasattr(object_name, "attribute")
                • Returns only true or false.
        • Concepts
          • Inheritance
            • When a child class is created, using a parent class as a template
            • class ChildClass(ParentClass1, ParentClass2):
            • Excpetion is a specific python class to create custom errors
          • Over-riding methods
            • A parent class method can be over-written by simply writing a method within the child class of the same name.
            • super()
              • Used to add additional functionality to a parent class without having to over-ride it and rewrite it entirely.
              • 1. Over-ride the class of the same name, then use: super().method_name(arg1, arg2)
              • 2. Add the additional functionality to that method, including return value.
          • Interface
            • When mutiple classes share the same method name, then it's said the two classes share an interface.
          • Polymorphism
            • Describes the effect when the same syntax can be used even if the objects they're used on are different.
            • Offers flexibility
            • Usually implemented through dunder methods
              • __iter__
              • __len__
              • __contains__
    • 8. Files
      • Every python script is essentially a file. We already know how to import a file using the file script_name import object_name syntax. Howeverworking with txt, CSV files and JSON files is just as important.
      • General
        • Opening files
          • Either use open() and the .close() function
            • open() requires the file_name as a string, the open type access (read, write, append, etc.)
              • "w" for write, "a" for append, "r" for read, and "r+" to have read and write access.
          • Or use the context manager structure, which handles closing the file automatically
            • with open(file_name_as_str) as text_file:
        • Reading files
          • Use the .read() method on the opened file_object.
          • Reading individual lines
            • .readlines()
              • Returns a list, which can be iterated through.
            • .readline()
              • returns only a single line
        • Writing files
          • Need to ensure that write access is granted using open() function
          • .write() method, assigned to opened file_object, which contains the data we want to write
      • CSV
        • Module: import csv
        • use .DictReader() on the csv_file_object to create a dictionary of row entries
          • Keys will be based on the first-row header entries
          • This reader method can be advanced using the delimiter keyword argument to read other delimited data-types
        • Note: when opening the file, use open(file_name, "r", newline=""
        • use .DictWriter() to write a CSV file
          • 1. Create the file using open()
          • 2. Create a .DictWriter() object
          • 3. On that object, use .writeheader()
          • 4. On that object, use .writerow(), assigning it an item dictionary (key.value pair) as an argument
      • JSON
        • Module: import json
        • JSON files have a very similar structure to dictionaries, and they are based from Javascript Object Notation
        • Reading JSON
          • Start by opening the JSON file using open()
          • Then use the .load() function on the file_object to read the data.
            • The output is very similar to that of a python dictionary.
        • Writing a JSON file.
          • Use json.dump(dictionary_name, object_file)

Images and files in the map

  • Programming Concepts

Information

Description
Mind Map on Programming Concepts, created by Adrien Gallet on 19/02/2020.
Created by
Adrien Gallet
Views
1
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?