Introduction: Python3
Have you ever wanted to learn a new programming language, one that has some features from other languages? Well, Python is your best bet.
There are three main versions of Python, these being "Python", or Python1, "Python2", and "Python3". These are like video game versions, as in 1.0 and 2.3 for an example.
This article will teach you the basics of python, and hopefuly you will be able to test your skills!
Understanding the Terminal
First, I will go over a few simple commands that usually take place from the terminal. The terminal is like a command prompt, where you execute different methods manually. This is what computers were like way back then, and I'm talking late 1987 back then. Have you ever wondered how computers run and function? With a very powerful command promt, thats why we need so much processing power nowadays.
Understanding Python3
Python3 is a very simple coding language. It allows the user to do lots of things, but it leans more towards utilities more (In my opinion), as in calculators and clocks. It does not have a lot of gaming functionality, unfortunately, so this article will teach you how to make a simple ASCII art image on the terminal screen. Note that this happens because you will launch the app from the terminal.
Understanding Strings
Strings are a type of variable ment to hold a "string" of letters held between two air quotes, like "this" or like 'this'. To define any variable you write:
var_name=var_contents
str_name="A Few Words"
str3 = str1 + str2
There is a way to "join" strings together, or merge them for the time being. The way you would write this is:
Understanding Multiple Lines
To make another line in a string, there is a special couple characters. These are "\n". What the "\" does is tell the computer there is another character after this resembling a special symbol or function. The "n" tells the computer that this symbol or function is a "New Line". This is useful for many purposes, but will be most useful for when we make some ASCII art, because it usually takes up multiple lines.
An example of an ASCII art picture I've made in the past is:
__
( )
( )
<≈≈≈≈>
|o|
|\ |
|o|
| /|
|o|
|\ |
|o|
| /|
|o|
\||/
However, you do not have to use "\n" to write a string using multiple lines. You can use a set of triple single quotes, which would end up looking like this:
''' __
( )
( )
<≈≈≈≈>
|o|
|\ |
|o|
| /|
|o|
|\ |
|o|
| /|
|o|
\||/
'''
Also note that even though when writing ASCII art as a string variable, the first line may not be lined up correctly to line up with the other lines. Try testing the alignment by finishing the script and editing the ASCII art as needed.
Understanding Print()
The easiest way to display something on the terminal screen is this:
print(str)
The "print" is the function name, the "(" and ")" are what tells the computer its a function, and the "str" is an arguement. Arguements are used in functions to pass data into the function. This is similar to the way you write the "echo 'Words'" command on linux, it takes an arguement, a string, and displays it in the terminal. An example of a "print()" script is:
str_to_display = '''
___
/ o o \
| ___ |
\___/'''
print(str_to_display)
Testing Your Knowledge
To finish off this article, lets test your new python skills. Hopefuly you remembered the techniques.
To run Python3 on your computer directly, which this section teaches you how to do, you must have a command line. For Windows, this is "cmd.exe", Mac is "Terminal" and Linux is (usually, depends on the distro) "Bash".
Because Python3 is a program, no, not a program like Scratch, but rather something used for executing specific file types, it needs to be installed. Because there are a lot of "mimicking" websites with viruses on them, I will show you how to download it through the terminal. The commands are:
Linux (Debian and Ubuntu) (Note that some systems already come with Python3):
$ sudo apt-get update
$ sudo apt-get python3
Mac (Bash Terminal) (Note that Mac systems may already come with Python3):
$ sudo easy_install pip
$ pip install python3
(Note that if you get a "bash: easy_install: command not found" error after running the first command, stop there. Use "$ sudo easy_install setuptools" to resolve this error and install the required package for the installer.)
Windows:
>py -3 ensurepip --default-pip
Please note that to verify the install of python, you can use:
python3 --version
in any command line after running these commands for your OS (Operating System, e.g. Mac, Linux, Windows). (Note that you do not type ">" nor "$" at the beginning of the commands, those are to symbolize the beginning of a command relating to your operating system so they are more user friendly)
To finish off, create an application by creating a "MyFirstApp.py" file (The "MyFirstApp" part can be changed), editing the file contents to display a cool ASCII art picture, and run the file from the command prompt using (In the same directory as the file):
python3 MyFirstApp.py
Please send a picture of your work to my email, this can be found on my home page, along with a picture of the end results and what article(s) you used for information to enter the Accomplishments Raffle. View more information on this at my home page.