Python Tutorials

Python is a general-use programming language. It was created by Guido van Rossum and first released in 1991, and has consistently ranked top ten of used languages since 2010. You can download the Python IDE from http://python.org. The beginning starts here:

Python Tutorial #1 – The print() Function

The first lesson you will learn is the most basic thing anyone begins with. The print() function allows you to output string values to the console. A string is a piece of text, like “hello,” or “yoyoyo,” and even something that is not a word like “65*$#(4749#.” The only rule is that the values have to be enclosed in quotation marks, as shown above. An example of something that is not a string is 5, or false. 5 is an integer, and false is a Boolean value. The syntax of the print() function is: print(arg), whereas arg is your string.

print("Hello, world!")

Python Tutorial #2 – Data Types

There are many different data types that are used in Python. These include integers, strings, floats, Boolean values, and even containers like lists, or dictionaries..

  • Integer – 5, 6, 1221, but not 5.5, or any decimal value. An integer is a whole number.
  • String – “hello,” “How do you do?” or “#^%&#%(!NJEGNJE*#HJE” are all strings. A string is a piece of text enclosed by quotation marks (” “), or apostrophes (‘ ‘). Tip: If you want to include quotation marks or apostrophes inside a string without getting out of it (” [quotation marks] “), you can instead use apostrophes to mark your string ( “hello,” he said. )
  • Float – 5.5, 3.0, 3.14159265358979, and other decimal values are expressed as floats. A float is a number with a decimal value, which surprisingly includes numbers such as 5.0, or 776.0.
  • Boolean Value – true and false are considered Boolean values. A Boolean value is a simple “yes” or “no,” and inn programming is “true” or “false.”
  • Lists – [true, 6, “hello”, 5.5] is a list. A list is a container for all data values, and can even nest lists in itself([[5, 6, [8,9]], 7]). A list is created with square brackets enclosing its values. Tip: the Boolean value true in the first example is marked with an index of 0, or where it is found. The 6 is at an index of 1, because it is second in the list.
  • Dictionaries – {“age”:11, “languages”:3, “codingEnjoyment”:10^10^10} is defined as a dictionary. You can visualize a dictionary as a key, or legend, that says “age”=11, and “languages”=3. They contain multiple values for each index, whereas index 0 would be age:11. If you wrote code that got index 0 (you will learn later), then you would result with the value, 11. They key of that index would be “age.”

Python Tutorial #3 – Variables

You’ve withstood my terrible teaching ability long enough to get here. The whole aspect of coding that one may say is the most important thing they had learned is variables. A variable stores a value that may then be referred to later in the code. For instance, one may define variable x, and give it a value of pi, then later need the value of pi, so they refer to x instead pi once again. Here’s an example of some code that may need variables. (DISCLAIMER: Not all things shown in the code will be showcased in this lesson.)

x = input("What is your favorite color? ")
print("Your favorite color is "+x)

In this code, I define the value of x by setting it equal to an input() function. The input() function receives input from the user via the console. I then print out, “Your favorite color is ,” followed by the value of x, or what the user typed in. You do not need to define your variable type before declaring it, if you are coming from other languages like JavaScript or C#. You simply need to state your variable name (x, in this situation), then set it equal to something like a function or data value (x = input(…)).

From here, I will take a short break. Soon, this page will come back with more tutorials, then more, then more. If you want to see some of my more complex codes for Python, comment below my newest Python post. See ya!