Python Basics – Print, Data types and comments

This tutorial will go over some very basics of python programming language

Part one – Print and comments

I know you guys are expecting a lot of flashy animated 3d 4k programming from python, I hate to disappoint you on that one but have a good reason which I will explain now.

Python is generally learnt at a console application level. If you go to your main start menu and type CMD and press enter you will see the command line interface or CLI. This is what we used to use before the beautiful GUI or graphical user interface.

Its kind of important that we learn python from a CLI point of view because that’s where all the basics are used. Now you might be wondering why in the world would I want to learn something that isn’t even used anymore? well fair question grasshopper but it is still being used JINX.

If you look at many big companies like ASDA, TESCO and many other retail outlets they do used CLI based interface because it’s cheaper to produce and doesn’t require expensive hardware to run. They can do stock takes, checks, reductions and other stuff with it and for cheaper. To maintain such software they need talented people who can operate and program in these things. Making sense now. Good, I know it’s a old interface and not very flashy but to get started in programming we need to learn the basics first.

Python is the easier programming language to learn and its very similar to other programming languages too, once you got the basics in the mix you are good to go and ready to learn and explore more if you like.

In this part we will learn about the PRINT and COMMENTS functions in python.

PRINT – print is a built in function in python which is used to display information on the screen. print generally works like this, you can start off by typing print and then put in the small parenthesis next to it like this print(). Anything you want to show in the screen will go inside the parenthesis.

In my first python installation tutorial we looked at it briefly now let’s look at in detail.

Print (  ”   ”  ) Hello World
Print(“Hello World”)

Look at it again. What we done here is very simple we called the print function and asked it to display hello world text to the screen. In order to do so we wrapped the Hello World inside of double quotations. This is called a string, we will discuss strings in more detail later.

Remember anything in between quotations is a string. A string is basically collection of letters.

Try these following commands in print

print ("Hello you!!")
print("My name is *******")
print ("I can see you lalala")

Print has many more functions which it can do, we will explore them as we go along.

COMMENTS – This one is kind of important but is ignored by many programmers. Commenting your code is another way to improve its readability. What’s the point of a code if a HUMAN can’t read it. I know you’re not writing for HUMANS but we kind of need them.. for now.. lol

Lets imagine you are working around the clock on a project with two other programmer who will take over you duty once your shift has ended. Now in order for you to visualise or note anything you will need to write it on a piece of paper or send them an email about what you done and where are you stuck etc etc.

2nd programmer comes to take over your shift and he finds some new code that’s been imported into the project he has no idea what you done or where to start. So he can either call you which will be crazy because you just left work or he can look through the comments you left on the code so you can get time off while he’s working. Once he finishes he’s shift he will do the same for you and it goes on.

Also its important for school and college projects to show that you understand the code and didn’t copy it from anywhere on the internet AHEM AHEM.

In python there is two types of commenting

One line commenting

print ("There is comment next you it but you wont see it") #Hello Im the comment

comments dont get compiled. Meaning when the program sees the # sign it won’t compile the line the reads after it. It will simply ignore the whole thing and move to the other ones. This way we can write anything we want in the comments and program will still run.

for example

print("python is soo nice") #its not really jk

It worked.

Second type of commenting is the obvious multi line comments

This we need in the same reason as before. Remember commenting for your school or college project is the only way to truly show you understand what you wrote. Get smart like right now.

Multi Line commenting in python: To use multi line is very simple

Use 3 single quotation marks such as this ”’ if you cannot find it, its the @ key on your keyboard just press it without the SHIFT key and you will get it.

Example:

print("There is a pointless multi line comment down here yak")

'''
Hello Python, nice to meet you.
I will be learning your programming language to overrule the world.
Yours Faithfully
lol
'''

 

Now include your own multi line comments in the program and check out what python will ignore once it finds the comments line.




Comments are closed.