What is Python?

Python is one of the most popular programming languages in the world. We can use the python language to give instructions to a computer to get it to complete tasks on our behalf. As you should expect, computer programming languages differ from spoken and written human language. Take English for example. The English language has a specific alphabet, dictionary of words, and grammatical / syntactical rules for how we construct sentences and documents. However, the English language also has many oddities and rule exceptions that make learning it complex. Thankfully, computer languages (Python included) tend to be more precise, and there are less rule-exceptions that we need to worry about.

When we develop programs (or “code”) we are writing a sequence of precise instructions for the computer to follow. As an example, take a look at the short python program below. This program is used to determine if a US citizen needs to get a new passport or not. US passports are valid for 10 years after the time it was created.

 1  import time
 2  current_year = int(time.strftime('%Y'))
 3  received_year = int(input('What year did you get your passport? '))
 4  if received_year + 10 < current_year:
 5      print('You should go get a new passport')
 6  else:
 7      print('You may use your current passport')

If you do not understand what is going on with that code, have no fear! We have not actually covered this material yet, I just wanted to get to show you some actual, real Python code that accomplishes something useful. I’ll break down what is going on piece-by-piece:

What Python programming function is used to show some text to the person interacting with the program? strftime() Not this one. strftime is used to get information about the current time. int() Nope. The int function is used to convert a value to an integer (this will be covered in a future lesson) print() Great! This functions primary job is to show text. This will be covered further in a later lesson

If you aren’t used to writing computer code, it may take some time to shift your brain into the right mindset. Writing code requires us to think critically, logically, and in a step-by-step manner. Some of you may not be used to thinking in this way, at least not for extended periods of time. In these early stages of your programming career, try to be cognizant about the mindset that you are going to take when you begin to code, but also don’t get stressed if it doesn’t come “naturally” from the get-go.

By the way, when we work with computer programs, it is often useful to have a text editor that has line numbers, as shown in the example. This allows us to easily see how much code we have written, where we are at in our code, and gives us a nifty way to refer to specific lines. Also, this lesson series is based on Python version 3. If you find yourself searching the internet for python code, tutorials, or documentation, you may encounter some code that is based on Python 2. Be careful of this, because there are a few differences between these two major versions.



PyFlo Home Complete Bookmark Next