Updated: Apr 12, 2022
Python is a popular programming language dating back to the early 90s. It is designed to maximize code readability and is supported by a large number of frameworks, particularly in the web sphere. The most recent version is Python 3, which differs from Python 2 in that it has a number of improvements to make code easier to write.
As a language, Python is largely used as dynamically typed, object oriented and procedural, but it is multi-paradigm and also supports functional programming and strong typing. It is also reflective, which means Python programs are able to modify themselves during execution.
Python programs are usually written in .py files. The language is split into a number of implementations, including CPython, Jython and IronPython written in C, Java and C# respectively. These different interpretations add extra pieces of functionality and quirks - such as Iron Python is able to make use of the .NET Framework, and JPython integrates with Java classes.
The core concepts remain the same.
Having set up your environment or installed an IDE, you are ready to start writing Python applications. You can follow the tutorial below to learn some core operations that can be performed in Python.
Note that the lines beginning with # are comments, which means they do not get executed in your application. The best way to learn is to type out these programs yourself (rather than copy-paste) as you’ll get a better feel for what it means to write Python.
# First, let's do a basic print operation
print ("Hello, world!")
If you run this application you’ll see the text string in the brackets gets output to the console. This is because ‘print()’ is a method, and we are calling it with an argument (our text).
We can make this a bit more advanced by introducing variables.
# Create a variable and print it
name = "Dave"
print ("Hello " + name)
The + operator when used on text strings concatenates them. As a result, we will see an output based on the constant “Hello “ being joined with the name in the variable. If, however, we add numbers together we will instead perform a mathematical operation:
# Let's do some sums
print (1 + 2)
print (1 - 2)
print (9 / 3)
print (2 * 5)
# Two *s raises the number before to the power of the number after
print ((2 * 5) ** 2)
One thing you’ll notice is that the division operator converts the result to a floating point number (3.0) whereas the other operations remain as integers. If, however, you use a floating point number in the calculation you’ll create a floating point result, as in this example:
# Output will be 10.0, not 10
print (2.0 * 5)
We briefly touched on variables before. It is important to assign values to a variable before you use it, or you will receive an error:
# This is OK
myVariable = 3
# This is not
We can also do conditional operations on our variables. Note that the indentation is used to separate code blocks, and until we de-indent our program, we continue to operate inside the ‘if’ block.
# The interior statements will execute as myVariable (3) is
# greater than or equal to 3
if myVariable >= 3:
print ("Condition passed")
print ("myVariable is more than 2")
# As a result, this won't execute
print ("Condition failed")
print ("myVariable is less than 3")
In this next example we’ll create a list by using square brackets and then iterate over it by using the ‘for’ keyword. This extracts each value in the list, and puts it in the variable ‘number’ before executing the block of code within the 'for' loop. Then the code moves on to the next item in the list:
# Let's count!
for number in [1,2,3,4,5]:
The Python code you encounter in the world will be comprised of these elements - methods, loops, conditions and variables. Understanding these fundamentals is core to being able to move on to more advanced concepts and frameworks, as well as being able to read and write your own Python applications.
Whether you're just starting out or you're an advanced python programmer, we have a tutor that can help you master your python programming coursework. If you're stuck on a question, submit your homework and one of our tutors will help you solve it! If you just want some extra help, contact a python programming tutor for a live tutoring session. We also have a homework library so that you can get some extra homework practice whenever you need it.
To fulfill our tutoring mission of online education, our college homework help and online tutoring centers are standing by 24/7, ready to assist college students who need homework help with all aspects of Python programming. Our computer science tutors can help with all your projects, large or small, and we challenge you to find better online Python programming tutoring anywhere.
for more informations contact us