Releases: JCR-Python-Programming/Lets-Learn-Python-Together-Updated
"Python Programmer's Glossary Bible"
"Python Programmer's Glossary Bible"
By Joseph C. Richardson
Hello and welcome to the knowledge of programming, with Python. Python is an object oriented programming language, such as C++. Python’s object oriented programming language makes Python very easy to understand, especially if you are coming from another type of computer programming language like C++; Python and C++ are very similar to each other. And as a matter of fact, Python derived from C++. However, with object oriented programming languages, there are no line numbers to type and there are no such things as ‘gosub’ or ‘goto’ commands. Instead, Python uses ‘functions’ to call for subroutines. Functions can also do much more than simply call for subroutines; we will get into functions later. Python is very picky about how you place your programming statements. Python executes/runs its programs from the top of the programming list, downward. If you don’t have some program statements on the right line of the program list, then Python will bypass those commands, or even execute them at the wrong time. It’s very important on how you type your Python programs. One other thing Python is very, very picky about, with Python programming it is imperative to properly ‘indent’ your code; you may need some practice to get comfortable with how to properly indent your code, without creating indentation errors and not knowing why. To remedy such unwanted indentation errors from occurring, simply press the ‘ENTER’ key after each line of code you type. The cursor will automatically indent for you on the next line; all you do is type your code and let the cursor do the indents for you each time you press the ‘ENTER’ key. Note: all indentations must be exactly in-line, or an ‘unexpected indent syntax error’ dialog box will occur. See example below:
Here are some examples of line-indentations in Python, which always proceeds right after the use of a colon (:).
For example, consider the following with yellow highlighted colons (:) showing where they are.
for key,value in dictionary_list.items():
print(key,value[0])
def my_second_function():
print('My second function.')
class Dunder_str:
def init(self,num1,num2):
self.num1=num1
while True:
while True:
os.system('cls')
if Boole==True:
if not Boole:
print(Boole)
For those such as myself, who are quite new to object oriented programming, it takes about a good year or more to fully start to understand it. But with a little bit of practice and patience each and every single day, your Python programming skills will get sharper as you learn. You will make all kinds of mistakes along the way, but that’s also part of learning anything new. So let’s get started and take the journey into the knowledge of Python Object Oriented Programming Language with my "Python Programmer's Glossary Bible". Because great programming always starts with a great programmer’s manual.
Tips & Tricks for Novice Programmers:
For those who are very new to programming, here are some very important things to keep in mind. When writing programs always create nice, clean and meaningful code; don’t create strings that are hard to understand. For example, create a string like this: name = ‘Jim’, not like this: n = ‘Jim’. Use meaningful names for strings of all types, such as character strings, integer strings, including tuples, lists and dictionaries alike. Creating meaningful strings also reduces accidental syntax errors from occurring in your programming code. Another very important thing to keep in mind is commenting your programming code so that you and other programmers, who are sharing the same project will be able to tell what parts of the programming code are doing what and such. Comments start with the '#' number sign followed by the commented word, or words. For example, # This is a print statement’s string variable ‘name’. Here is another example of what a comment might look like, # This loop counts all the items in the names list. Comments help the programmer express in meaningful ways how the program works and other programmers can easily pick up the pieces when they take over the nightshift. Another type of comment is with the use of three single quote marks (''') at the beginning of the comment statement and at the end of the comment statement. This type of comment can hold complete paragraphs, whereas the '#' comment statement can only hold words on a single line. The two examples of comments are as follows:
This is a comment statement on a single line.
'''
This is a commented paragraph statement, which can hold a complete
paragraph about the program and how it works. You can use as many
lines of commented words as you please.
'''
Note: comments do not execute/run, while a program is executing or running. Comments are ignored by the program; only the programmers know that comments exist within the programming code. As you study the "Python Programmer's Glossary Bible", you will constantly notice how everything written is in the form of these, two types of comment statements.
Case Sensitivity
Case sensitivity in programming of every kind is very important to understand. This means that text must be typed correctly. For example, if you type a string's variable name with a capital letter, then you will also have to keep using that string's variable name with a capital letter. Likewise, if you type a string's variable name with a small letter, then you will also have to keep using that string's variable name with a small letter. However, programmers understand case sensitivity as 'Uppercase' and 'Lowercase', which simply means 'Caps and Non-Caps.
For example, take a close look at these two string variable names. (A='Value') and (a='Value'). Both of these strings are exactly the same, but with one exception, the variable name 'A' is also shown as 'a' in the other string variable name example. To gain a much better understanding of case sensitivity in programming, here are two examples of yellow, highlighted string variable names, which involve case sensitivity in the Python code. For example, consider the following:
Correct case sensitivity
A='Value'
print(A)
a='Value'
print(a)
incorrect case sensitivity
A='Value'
print(a)
a='Value'
print(A)
If you take a close look at these two Python program examples below, you will clearly see how case sensitivity works. Both variable names are of the letter 'A' and 'a', but Python thinks they are different variable names that belong to different values. So it's very important that you always keep string variable names with different, unique letters to avoid any potential naming errors, which may occur, such as in these two illustrated Python program examples below.
A=" I'm the Value for uppercase A "
print(A)
a=" I'm the Value for lowercase a "
print(a)
However, case sensitivity doesn't stop at string variable names alone, input statements are also governed by case sensitivity, so are classes and functions alike. Some Python commands start with an uppercase letter, such as 'Canvas, Label, Entry, Tk(), True, False. And some, such as class functions always start with a capital letter in the variable name as a standard, but lowercase letters can also be used in class variable names as well. Note: most, basic string variable names are usually written as lowercase letters as a standard, but uppercase letters can also be written as well.
DRY (Don't Repeat Yourself)
When it comes to programming, especially those who are brand new to programming will often write repetitious code, without realizing it. Repetitious code simply means using the same code, or command statements over and over again. For example, consider the following:
Don't Repeat Yourself!
print("Hello Sun!")
print("Hello Moon!")
print("Hello Stars!")
print("Hello World!")
Keep it DRY!
words_tuple=("Hello Sun!","Hello Moon!","Hello Stars!","Hello World!")
for words in words_tuple:
print(words)
Single-Line Multiple Command Statements
Python supports single-line multiple command statements, which means most command statements can be written on the same line using commas (,) as command-line separators. For example, consider the following:
print("Hello Sun!")
print("Hello Moon!")
print("Hello Stars!")
print("Hello World!")
print("Hello Sun!"),print("Hello Moon!"),print("Hello Stars!"),print("Hello World!")
Python supports single-line multiple strings, which means multiple strings can be written on the same line using semicolons (;) as string separators. For example, consider the following:
string_1=' "Python'
string_2="Programmer's"
string_3='Glossary'
string_4='Bible" '
string_1=' "Python';string_2="Programmer's";string_3='Glossary';string_4='Bible" '
print(string_1,string_2,string_3,string_4)
Python supports single-line multiple import function statements, which means multiple import function statements can be written on the same line using semicolons (;) as import function statement separators. For example, consider the following:
import os
import time
import math
from math import*
import winsound
import os;import time;import math;from math import*;import winsound
import os,time,math,winsound;from math import*
Note: to keep things simple, especially for the novice programmer, all program statements and program examples will remain on separate command lines. To the novice programmer, this is especially important to be able to mitigate any programming errors, which will occur from time to time as you write programs, especially complex programs. However, it is good practice to keep nice, neat program code on separate command lines to make it easy to understand; professional programmers prefer such.
Writing Dirty Code Programming
Now, let's talk 'dirty'. I mean, let's talk about 'dirty code programming' and why you shouldn't do it. What dirty code...