Teardown of our first program
Be patient while you read this as there are a lot of new terms, but do not get stuck on them, We will go on a deeper dive in further articles. If you still cannot handle the gap then do ask in the comments.
Previous: Interacting with Console
These are the following topics which will cover our understanding of our first program:
- Keywords
- Syntax
- Pretext to Functions
- String
- Errors
print("Hello world!!!")
Keywords: Vocabulary of the language
The print
statement/word is responsible for writing to the console, or we can say print
keyword when translated by Interpreter of python means write to console in machine language.
These types of words or statement in a programming language are called keywords. They have a specific meaning to the computer when translated. We can also say that they are the vocabulary of the language.
Syntax: Grammar of the language
Now a language cannot function without punctuations and grammar, can it ?
There are various punctuations like:
" ' : , ( } . @ [ all special characters except underscore(_)
While grammar defines the proper usage of vocabulary and punctuations. You can see how parenthesis() and quotes (“”) are encasing our message, which follows after the keyword print
.
This is called Syntax (grammar) of a programming language, which defines how keywords (vocabulary) and special characters (punctuation) are used.
Pretext to Functions
Now we will learn the meaning behind this particular usage. Some keywords in python are followed by parenthesis() which identifies the keyword as a function (We will learn more about functions in further articles).
To perform a task, sometimes we require some inputs for e.g. we need tea leaves and water (inputs) to make tea (output) similarly, Every function can accept some inputs to do the task, in this case the print
function accepts the message we want it to write on the console.
The input is encased in the parenthesis(), In our case which is "Hello world!!!"
.
String: A data type
You can also see that the message itself is encased in the quotes (“”). Why you ask? Because the print
function accepts a value which it can write, which should be our message.
Now let’s try these statements print(Hello world!!!)
and print(Hello)
messages without quotes (“”).
What happened? Why does it says error?
Python language does not understand that by Hello world!!!
or Hello
you mean that it is a message which can be written onto the console (since it is given to print function).
A message or text can only be identified by encapsulating the message in quotes (“”). That means python identifies that anything between quotes (“”) is a message or text. This is called string, a data type representing text.
print
function accepts a string as an input and writes that onto the console. It also accepts other data types, but we will explore them later.
Errors: Difficulty of python interpreter
Now let us understand more on these errors:
1. Syntax Error
This error tells us that there is an improper usage of syntax (grammar) of the language. Meaning, python is not able to understand the meaning of space in Hello<space>world!!!
.
2. Name Error
This error tells us that there is a usage of a keyword (vocabulary) which is not defined. Yes, we can define our own vocabulary. We will learn how to do that in the future.
Congratulations !! That’s it. You have understood a great deal of things from a single line of program. You have come far.
Next: Data Types in Python