Python

Python is a language you can use to work quickly, integrate systems, build websites and program artificial intelligence. Just like language is the basis of human consciousness, these computer languages, like C, C++, QML, SQL and Python are the basis of the artificial intelligence we are developing on this planet.

Python and PHP are two different languages that accomplish essentially the same thing. They’re like the Ford and Chevy of programming languages. You can use them to build the back end of your web applications.

Python is relatively easy to learn. It is often used for developing artificial intelligence. It is one of the most popular and fastest growing languages. Apparently, it is relatively slow.

Read the manuals. Over and over again. It seems like the more I learn about computer science and website development, the more I need to learn.

For every answer I learn, I discover three more questions. Be patient. You’ve got to make sure all the pieces of the program are properly connected to each other. You may have to links some files together, to get everything to work right in your computer.

There are two major versions of Python. Version 2.7 is baked into Linux and so it is still maintained and used by a variety of people. Version 3.9.2 is the latest version available as I am writing this story.

Django is a fully featured web framework originally designed for a news website. You have to follow the strict Django format. It will be a good way to learn how to program using Python.

Flask is a micro-framework which allows you much more design freedom than Django does. It will allow you to experiment and create your own freelance website designs.

Fundamentals

Keywords are words reserved in Python for describing certain operations or types of data. There are several keywords that cannot be used as variable names. if, else, elif, and, or, not, class, while, break, continue, yield, import and def are some examples.

Variables are names that you give to data that you want to store and manipulate in your programs. For example, you could use the variable userName or userAge to store the actual name or age of a user.

Variable names can only contain letters, numbers and underscores. The first character of a variable must be a letter or underscore. Other characters can be any combination of underscores, letters or digits. Names starting with an underscore are usually reserved for a particular class. Names that begin and end with double underscores have special meaning.

Dunder objects or magic methods and magic attributes are represented with names surrounded by double underscores, like __this__. [7]

Variables can be local variables, which only work inside the function they are declare in; or global variables, which can be called from anywhere in your program. [1]

=, +=, *=, -= and /= are combined assignment operators.

**    Exponentiation
*     Multiplication
/     Division
//    Ground Division
%     Modulo (Remainder of Division)
+     Addition
-     Subtraction

are mathematical operators.
[1]

Data Types

Integers are whole numbers. Floats are numbers with a point, with one or more digits after the point. The digit after the point could be zero. There are several other mathematical data types.

char are individual characters. They can be letters or numbers. Strings are text, which can include numbers. Strings are immutable, which means they cannot be changed. The string input prompts a user to enter some information. Declare a string with: [1]

variableName = "initial Value" or
variableName = 'initial value'

Example:
userName = 'James'
userCity = "Seattle"
userAge = "25"
[1]

Lists

Lists are collections of related data. Tuples are immutable lists, which can only be replaced, not changed. A dictionary is a collection of related data pairs, such as {“name”:age, “Bob”:60, “Dave”:43}. Very similar to JSON data.

Python uses the index method to find the position of an element in a list. If there is more than one instance of an element, it finds the first instance.

The slice function returns a slice object. A slice object describes how to slice a sequence. You can specify the beginning and the end of a slice. You can also specify every other item or every third item in a list, etc. [3]

Python Interpreter

The Python Interpreter is the program that you start by typing python3 onto your command line. It will introduce itself and present a prompt with three greater than signs, like so: >>>. Three dots: … , is a prompt continuing a previous prompt.

A # signals the beginning of a comment. Everything after the # to the end of that line, is a comment.

Python uses indentation to group statements. [4]

Control Flow

if is one of the most common python statements. Zero or more elif statements can follow an if statement. elif means else if. An else statement can also, optionally, be added as a final option of an if statement.

Python’s for statement iterates over any sequence of items in the order they are listed. You can modify the list you are iterating over while you are inside the loop. Make a copy of the list, before modifying it.

The range() function generates arithmetic progressions. You can specify the beginning and end of your range. The range does not include the end point of your range. So range(5, 10) would include 5, 6, 7, 8, 9. You can also specify an increment or a negative increment, range(0, 10, 3) generates 0, 3, 6, 9. Negative increments count back from the end of the range.

A break statement breaks out of a loop. A continue statement skips the present iteration and moves on to the next one. An else clause is often the final iteration of a loop.

Use the pass statement when you need a statement for syntax reasons, but your program does not need to do anything.

The keyword def represents the definition of a function. It is followed by the name of the function, and a list of parameters inside parenthesis. Statements that form the body of the function are indented on the following lines.

The first statement in the function can be a documentation string, docstring. You can use certain tools that use docstrings to automatically produce documentation that you can print out and/or present online.

Executing a function introduces a new symbol table for the local variables. Variable assignments store values in the local symbol table, unless they are declared global. Variable references first look in the local symbol table, then in the local symbol table of any containing functions, then in the global symbol table.

Parameters (arguments) of a function call are introduced in the local symbol table of the called function when it is called. Arguments are passed using call by value. In other words, the value is always an object reference, not the value of the object. A local symbol table is created for the call, whenever a function calls another function.

A function definition introduces the function name in the current symbol table. The value of the function name is a type recognized by the interpreter as a user defined function. [4]

Sources

1 Brian Overland, John Bennet - Addison-Wesley - Supercharged Python - 2019
2 Julian Danjou - William Pollack - Serious Python - 2019
3 Jamie Chan - LearnCodingFast.com - Learn Python in One Day - 2017
4 https://docs.python.org/3/tutorial/index.html
5 Irné Barnard - https://www.quora.com/Which-programming-language-is-Linux-written-in
6 https://ostoday.org/linux/what-language-is-ubuntu-written-in.html
7 https://www.djangospin.com/python-dunder-methods-attributes/