revised due to me forgetting to add branching and if statements. probably add more stuff in the future.
I first want to start off by this post is more of a reminder for myself, than a tutorial. I like to plan just in case for whatever reason, I forget how python works, I want to have a reference for me, by me. It doesn't have to make sense to you but whatever. Take it or leave it.
I will also include a link to an online compiler. I am sure that there are libraries for me to use that can create an online compiler, or if not, since this website is powered by WordPress, and Minimally python, I'll figure something out and update the post if no other solution is added to this blog page.
below is a sample from a python script, ran in PHP to be output in a WordPress shortcode, thus a successful integration of python3 into a WordPress shortcode being utilized as a display end for python3. Youtube-dl is a python library. This is proof of python being called from WordPress PHP.
You Dun' Fked up naow!
type in the box
and click the compile button
too lazy to work on security for ide so doing kode from trinket.io
if you did it right, the output should be "racist liberals". see?
Try out to your heart's content
see? it's easy to get started with python.
Now. Onto the hard part.
Setting up python
Now, to get python on your computer, you will need to go to the python website and download it
. You could also download pydroid 3 from the google play store on android phones, and also use that.
If you have a windows computer, you would download the exe or MSI file, and run it. Follow the instructions and after it says it installed successfully, you can run python, or use the companion ide (IDLE I think it's called.) or use the bash shell to type it in.
If you use MacOS, since apple sucks in general (more than you think, less than it should), download the dmg file and follow the instructions. I ain't doing shit about apple or anything.
If Linux is your operating system, then you chose well young padawan (star wars. It sucks now. RIP STAR WARS). But this method will be a little bit more involved. Examples will be from Linux lite os I use. It uses Debian and ubuntu so there are means of installing python. Linux comes by default with python so if you want to upgrade your python version, more or less what it involves, then this instruction set is the way to go.
Generally, you will be given the tar.xz compression file extension (.zip in windows compressed files) and will need an extraction software to open. What I did was create a program files directory to organize my software like on windows and extracted all of that there, but you can extract where you want to.
I am going to do a copy/paste of the readme.rst file that should come with it. In case for whatever reason you can't parse it ( you can check python website, stack exchange, or even github as python is open source) so when you type in the following, you would need to use a terminal, or sometimes it's called terminal emulator. It's to linux what the bash shell is to windows, just a terminal interface.
On Unix, Linux, BSD, macOS, and Cygwin::
sudo make install
This will install Python as ``python3``.
You can pass many options to the configure script; run ``./configure --help``
to find out more. On macOS case-insensitive file systems and on Cygwin,
the executable is called ``python.exe``; elsewhere it's just ``python``
While you can install with optimizations, we will skip for now, and you shouldn't run into any problems. You can use a text editor to write python code, but I recommend vs code. They call it a IDE (or integrated developers environment) and I have developed my own, use vim via terminal or even edit from my mobile android (via PyDroid 3) but I am well in the years and mastered engineering, so for you, I would recommend using vscode (even though bill gates is a bigot, and Microsoft sucks) starting off. If you use windows you can use both vscode or visual studio. Linux you just use vscode. I ain't going no more into it. Find out for yourself.
When you type in `sudo make install` and it finishes, it would make your `python3` version to the most recent version. As of 09-26-2021, you shouldn't need to upgrade your standard Linux OS python to follow the tutorial, but this is only if for some reason, you don't have python on your Linux machine, or you want to upgrade from python 3.8.5 to 3.9.7. Refer to the readme from the python or github python page (use duckduckgo (or racist google)) for more information.
Your python scripts are going to end with a .py extension so if you decided to do a hellopy file, you naturally would save it as hellopy.py. If this is a challenge, please get basic computer usage courses, all free on sexist youtube. Other than that, lets proceed with breaking down a python script.
import os #importing libraries for additional functionality, from basic outputs to hell a fucking game engine
_01_dis_is_a_variable = "variable" # variable is a container for data. variables cannot begin with a number unless there is an underscore that comes before, and you cannot use a reserved keyword (more on that later)
def _test_function(parameter): #function subroutine is what you use to bundle a set of codes to call in sequence whenever called
return parameter #return keyword would return the data as given. more later as full understanding will not be expressed in this comment
#by the way this is a comment. comments are not red or executed in the code. It is a placeholder or you use it to
#communicate which each variable, sequence, function etc. does. Just think of taking notes.
_test_function(_01_dis_is_a_variable) #this is calling the function which should print "variable"
For the rest that decided to proceed, I will break down what each means and how it will evolve. Ready? too bad. Since I can't safely get laid, you gotta suffer! I would go onto the playstore and utilize sololearn, udemy, eduonix, edx.org etc. Training is free, and mobile apps are designed carefully to keep you engaged. If I could collect affiliate links for people to bring them in, I would be making even more money. But you're here, so I will not waste your time. Let's proceed.
imports and variables
Well since you will be using variables throughout your code, we will need to discuss it. In a simple explanation, variables are described as containers for storing data values. Try to think of variables as placeholders for data. there are many reasons to use them. They can help the programs you would write to become more flexible. A variable is used to allow the programs you write to refer to a variable's value in one location, instead of having to type out the values you would need. As I said before for the slower Kidz in the back, as rules for naming a variable, you don't want variables to conflict with function names or reserved keywords, and since you cannot start a variable name with a number (unless an underscore ( _ ) is inserted before the number i.e. _01_data_var. Also another rule to keep in mind that with upper and lowercase letters in a variable name, They are interpreted as different variables so for example, _01_Variable, _01_variable, _01_VARIABLE, _01_VariaBle are all different variables. so you cannot use _01_variable as a substitute to _01_Variable, unless you code it that way, but we won't get into that for right now. It's better to understand as things go along.
In Python, variables don't need to be declared with any specific data type. But another thing to keep in mind is that variables can change the variable in question's data type after they have been set, so be careful and keep this fact in mind.
print = print("Uh oh!") #Will cause an error and can cause your program to break
This will cause an error as you tried to name a variable after a reserved function. There are ways of doing that, but this way, will cause errors. Witness how these things work, few examples of what to do, and what not to do.
exampleVar = 55
The example below is not a valid datatype, and this will cause an error. You would need to throw quotes around the string.
cannotDoThisCrap = HeyFucker!
canDo = "HeyFucker!"
Hell, you are able to store the result of a calculation to a variable.
canpop = 5/4
You can set functions as well, but not reserved functions, nor keywords.
Try the examples below:
Got it? good! now we can move on....
Code written in python, is organized in modules & packages. On the Python.org website, it states that the definition of module is an object that serves as an organizational unit of Python code. Modules have a namespace containing arbitrary Python objects. Modules are loaded into Python by the process of importing. When implemented, a Python module is usually one .py file containing Python code. The magic of this tho', is that modules can be imported and reused in other code. For example...
# should output 3.141592653589793
on the import math part, you end up importing the code in the math module and make it available to use in your script. The second line which has math.pi inside the print function parameter, this is where the "pi" in the math module you can access. Pi is the variable in the math module. Since the math module is part of Python's standard library, you can import it anytime you need. Also to note for the slow kids in the back, modules can act as a namespace that will keep all the attributes of the module together. Namespaces are used for keeping your code organized and in most cases, readable.
Packages are different. In the relevancy to it all, modules generally are composed of only one py script, and packages have many scripts, and sometimes can also depend on a binary executable, and be located in it's own directory.
A package is still a module tho. To create a Python package yourself, you create a directory and a file named __init__.py inside it. The __init__.py file contains the contents of the package when it’s treated as a module. It can be left empty if need be. Directories can be treated as packages without an __init__.py file. However, these aren’t regular packages, these are known as namespace packages. I'm sure if you kept up this long, you'll figure it out later.
try this below:
# Import math Library
# Print the value of pi
Functions are more or less a block of organized, reusable code that is used to perform a single, string of actions. Functions generally provide better readability, and generally provide a good portion of code reusing.
Take for example that python gives you many built-in functions like for the damn print(), etc. but you can also create your own functions call it fucks for all I care. These functions are referred to as "user-defined functions".
As you know, functions can be defined to provide the required functionality. Here are some of the fucking rules to follow when your lame ass define a function in Python:
Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ). eg. "def _03_fuk_urself()"
Any input parameters or arguments should be placed within these parentheses. You can also define parameters inside these parentheses. eg. "def _02_eat_dirt(eeb, fap="splash")"
The code block within every function starts with a colon (:) and is indented. eg. def _24_somokz_zum_weed(strain): notice the colon
def _02_supa_drive(vroom, engine="vx"):
The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None.
return "I am".sucker.",And I deserve nothing but spit on my face, and disrespect, because I'm a pathetic simp"
Homework to do when you move to next section:
You can call a function by using the following types of arguments −
Google (preferably duck duck go, since google is racist.) each of these arguments and test them out on this ide or the other IDEs.
Python while/for loops
I would honestly rather have the w3 schools explain it, as it is a source I have learned from and it's simple-simple. I could say that you could type in x= 100 while x > 0: x -= 1, but there is more information on these loops. The W3Schools website here in this link has it's own and simplified details on it's site. Plus examples and break and continues and stuff. click here to learn interactively.
Don't like it? Go Fuck Yourself! I'm not about to make it easy for you. You wanna be a python programmer? Take this "Homework" and swallow some knowledge, faggot. Do your research, punk! You lucky I left the link above for you to use to get a headstart. You wanna learn to make a game loop? the while loop is fundamental. so yea. This section will be homework for you. You learn this on your own, entitled ass butt snob!
, Think of classes as a structure for a datatype. A blueprint if you will. For example standard datatypes include int, double, float, boolean, etc. Creating a class can be thought of as a "Blueprint structure of a custom datatype". Since I am lazy, I am going to webscrape this section from tutorials point from directly off their website. Their website link is at the bottom if you don't believe me. Follow the link. See for yourself I got lazy. I can be a lazy coder cause I gots skills. These are the basics you need. If you have questions, Google (or duck duck go) stack overflow and type your question in the search box.
TEST YOUR MIGHT
just have fun with this environment. You can't save scripts but you can practice your python skills here. You don't have to leave this page until you at least have a good idea of python works, then you can go ahead and get those independent certs online instead of going to a sexist college/ ivy league school. They heavily discriminate against men and boys.