Welcome! This a website explaining the basics of the popular programming language, Python!
Python was first released in 1991 as Python 0.9.0. Subsequent developements led to the production of Python 2 and 3, released in 2000 and 2008 respectively.
Python has remained consistently popular amongst programmers all around the world for its ease of use, specifically its syntax which is highly similar to human language and the use of indentation to indicate blocks of code.
Because of the language's still growing popularity, a wide variety of courses teaching the language has been made available on the web, both free and paid. Python is considered one of the most beginner friendly languages because how it primarily makes use of indentation, which makes writing and reading code highly intuitive and less intimidating, which can scare off the uninitiated.
This webpage will go through a couple of simple examples of what Python can do, and how to do them with actual code, so you can experience first-hand the readability of the code which can hopefully inspire you to write your first lines of code!
A staple in many online programming courses, regardless of language, is the concept of loops. How can you get the computer or a program to do the same thing multiple times? What if you have specific conditions to meet for the program to start or stop? We wouldn't want something to go on forever do we. That's where loops come on. The word itself suggests repetition, but in programming, repetition is typically executed with conditionals in place, which you will see demonstrated below.
for i in range(10):
print(i)
# the code above outputs the following:
>>0
>>1
>>2
>>3
>>4
>>5
>>6
>>7
>>8
>>9
Notice something weird? Interesting how the program doesn't start printing from 1, but 0 instead and how it stops "short" at 9? This is actually how the many programs and languages work, meaning that counting starts at 0, and stops "short", excluding the final value.
i = 0
while True:
print(i)
i++
The code snippet will infinitely print numbers incrementally, starting from 0. Well, not infinitely, up until your computer runs out of memory, causing it to crash and burn. Neato!
i = 0
while i < 50:
print(i)
i++
We've added a condition so that the program stops printing when the value of i hits 50, saving your computer from oblivion. Phew!
These are just one of the many, many ways loops can be initialized and used, which you will definitely learn along your programming journey. Gotta code em' all!
Remember the code snippet above which printed 10 values? Well what if you wanted to print out more values? Or if you wanted to run the snippet multiple times? You might have to copy paste the code as many times as necessary.
But luckily for us, we have a more elegant solution for that. Enter functions, which tout customizability and reusability. Creating a singluar function allows us to reuse it multiple times without having to type as much code. See below!
def print_numbers(number):
for i in range(number):
print(i)
print_numbers(20) This code prints numbers from 0 to 19.
print_numbers(101) And this one prints numbers from 0 to 100!
def print_numbers(number, name):
for i in range(number):
print(i * name)
print_numbers(20, "charles")This function will print the name "charles", starting from none, then once, then twice, and then finally 19 times. You can do the math yourself. That's a lot of "charles"es!
Using functions, we can repeat the things we want to do with significantly less code, less copy pasting and with added customizability to suit our needs! As always, this is just a simple demonstration of what functions can do. Smart people have built upon this simple concept to come up with full-blown apps that we all use and enjoy today! Hopefully this taster has inspired you to begin your programming journey. Go get em' tiger!
Maybe after this short website you're thinking: "Wow, Python's really cool! Where can I learn more?" Listed below are some links to help you get started!