Python is a powerhouse programming language capable of supporting you throughout all your programming adventures. Making exciting and unique code is just flashes of comprehension away. For those just starting, looking at the Python Program Window the potentials can seem immense. It can leave you wondering just how exactly do I begin my Python journey? The answer to this, my dear reader, is by writing a 'Hello World' script. So let us dive right in and start learning Python!

Transcript

Hey gang! Tim here from Core Electronics and today we're diving back into the world of the programming language Python.

Python is that powerhouse programming language capable of supporting you through all your programming escapades effectively controlling computers is something that every modern maker should have some grasp of.

A big part of understanding with Python comes from having a grasp on functions and writing scripts. For those just starting looking at the Python program window, the potentials can seem immense it can leave you wondering just exactly how should I begin my Python journey and the answer to this, my dear viewer is by writing a hello world script.

So let's dive right in and start learning Python this guide will introduce the concept of variables, strings and functions it will also be a dive into what those programming files are saved as and also give an analysis of code by the end of this guide we'll have created and executed a new python program this will instruct our computing device to announce in five different ways “hello world”.

Jumping into the computer you can see I have the programming window open and the Python idle shell ready to go, I’ll start off with the simplest example of the print function and use it to display “hello world” a function is a block of organized reusable code that is used to perform a single related action that only runs when called upon, the print command is typed in Python as “print bracket bracket”, so starting off let's write print, you'll notice that it comes up in purple demonstrating that as a function, first bracket, quote “hello world”, exclamation mark comma not comma quote, right the print function requires parentheses to be invoked and they cannot be used with curly brackets. So this basically means all the information you want to be printed needs to be inside parentheses to print characters you must enclose the data in single or double matching quotation marks and this is to ensure that the characters inside these quotation marks don't get mistaken for something else, like a keyword more on that in future content, now quotation marks are not required if printing a number so if we run this code by using the drop down menu it will ask to be saved as a Python file so we'll say yes, saved as a Python file throw in a desktop and we'll call this “first script” something along those lines and as you can see it's now run as a heads up, small scripts will have a very small byte size so by the end of this tutorial if you're following along writing your own script it will be something along the lines of two kilobytes so once it's saved as you can see the Python idle shell displays the results of the script after it's been run and here it is “hello world” you can see the results of the code and they'll be stacked up on top of each other in blue, looking at the run code you can see above the results is the exact location saved to the computer of this code.

Above that is the exact version of python being used, as well as the date and time, the bottom right of each window tells you exactly where you've left your cursor, the text cursor by the line number and also by the column number, the text cursor can also be altered by clicking elsewhere in the code, this is true also for the python programming window.

So let's keep diving into different variations of the print function, let's use the print function to create two separate strings and print them together, so a string in python is a sequence of characters be it letters, numbers, white space, punctuation enclosed by quotation marks this concept will be dived into deeper in future content. Print, bracket quotation mark, this time we'll use double quotation mark to demonstrate this and I’ll give a little bit more space too because we can do this without it showing up, in the shell, hello again, space, worth remembering that plus, got to use the same quotation marks plus another quotation like world, exclamation mark, quotation mark, bracket, in this now, the hello again is a string and the “world exclamation mark” is a string. When this code is run the result is “hello again world” combined together as you can see here so now the print function also allows you to separate what is printed with a paragraph using “forward slash n” to denote a new paragraph, I’ll type out an example of this; print bracket, double quotation mark, hello, forward slash n, once forward slash n again, forward slash, n big forward slash, n world exclamation mark, double quotation because that's what I used, bracket to finish, segregate a little bit more. So when I run this you'll notice that all the words have been given a paragraph to separate them and you won't see the forward slash n, first one, second one, third one, “hello again, hello once again big world!” it's separated by paragraphs.

So let's go into another capability of the printing function which is having all the printed info displayed on a single line but allows a delay to be coded in between the first and second part I’ll type out an example of this, print once again, bracket, comma, guess what, dot dot quotation mark comma and equals quotation quotation bracket, so right here you could code in a pause, this end quotation quotation is searching for the next print function, so now if I type print quotation mark hello world quotation mark bracket this print is what's going to be substituted in to that end equals, so now if we run this. You'll see our previous three and then you'll also see “guess what… hello world” now as there's no code delayed between these two pieces, this will print guess what hello world effectively to the human mind instantaneously it's very fast so the final method of printing “hello world” which I’d like to talk to you about uses a variable with identifier X so below let's tell the computing device what the value of X is, so X capital X, X equals bracket quotation mark, final will convolute a little bit by adding more quotation marks just to demonstrate that you can do it like this hello quotation mark, keep in mind you want space bars included in this otherwise it will all be bunched together the text will be bunched together, well quotation mark bracket, now in python lingo what we created here this is referred to as a string variable so a variable is a named location used to store data into the computing device's memory, imagine variables as a box filled with books and each of these books, can be like changed replaced or altered so every variable in python must have a name which can consist of letters numbers and or even the underscore character, now using the print function to display the variable X with an exclamation mark at the end so let's, so this just writing a variable won't print it to the console but if I do this print X and I’ll add an extra complication so we're printing the variable end equals quotation with exclamation mark notation bracket what this will do is at the end of final hello world it will add an exclamation mark so without further ado let's execute all of this, this is our first python script and this code will produce five unique different hello world variations.

I hope this has demonstrated how functions exist and how they can be used in Python. I’ve also hope this shows you the capabilities of the print function there are many, many, many functions in Python that do different things and each function has a depth onto itself, so the online write-up for this topic spends some time coding in an online Python emulator this is to highlight differences between running the actual program and also running an emulator also available on our write-up is a Python file similar to this available to download, you'll notice that if you download there'll be lots of comments which are written in red and python in python any written text after a hash will be a comment which I can demonstrate now.

“This is a comment” this comment will extend until a new line character is used for example the enter key python interpreter will completely ignore comments therefore any text written as a comment will have no impact on the final program, correctly used they will describe what's going on inside the program so that another person or you in the distant future will be able to look at the code and quickly understand what's happening, key details can easily be forgotten in a couple of weeks and you will definitely save time as a programmer by employing good commenting habits, so there you have it making exciting and unique code is just flashes of comprehension away, future content will involve expanding your repertoire of tools learning about variables functions keywords and operators I hope this has been helpful and inspired some future programming endeavours into your life until then stay cosy.

Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.