Python First Program
Writing a python program is as easy as typing plain English. For our first “Hello World!” program, we just have to type print("Hello World!")
in the Jupyter Notebook.
It’s amazing that how simple it is to print ‘Hello World!’ in Python. We don’t need to do any heavy lifting, such as importing files, as we do in other programming languages. A single statement is all it takes. It’s as easy as it sounds.
print("Hello World!")
Here is the simple breakdown of the First Python Program, which contains the print keyword and the content that we want to print. This content can be the text, number or the variable.
Python as Calculator
A Python interpreter can be used to perform calculations like a regular calculator. We can accomplish that by simply typing the actions we wish to take instead of creating a program. We can perform calculations like 5+5, 789*456, (14+2)*(5+3), and many others, for instance. All of this is possible without even writing a single line of code.
5+5
789*456
(14+2)*(5+3)
Python Version
It is easy to check the version of the python interpreter we are working on. Three ways by which we can check the version of the Python interpreter:
1.
In the Jupyter notebook or any other IDE, we just have to import sys
and then type print(sys.version)
.
import sys
print(sys.version)
2.
There is yet another method by which we can check the version of python directly from the command prompt. We just need to go to the command prompt and type python --version
.
3.
We can also import platform
and then use print(platform.python_version())
to check the version.
import platform
print(platform.python_version())
These are just three techniques to check the version of python. But we can also check the same using some other methods like help(), when we will use the help() function to check the version, the first like it will display is “Welcome to Python 3.7’s help utility!”. Some people use this also as a technique to check the version of Python because for this they don’t need to remember any of the above mwthods.
Keywords in Python
Keywords are reserved words in Python that have special meanings and cannot be used as identifiers (variable names, function names, etc.). We should avoid using these words as variable names to avoid conflicts and ensure proper functionality of your programs.
To check the list of keywords, we just have to import keyword
and the type print(keyword.kwlist)
. It will print the list of keywords.
import keyword
print(keyword.kwlist)
Here is the Table showing all the keywords available in Python:
Keywords are essential building blocks that define the language’s syntax and structure. They are predefined and serve specific purposes within the code. Common keywords include if, else, for, while, def, and class, each playing a crucial role in control flow, function and class definition, and more.
For example, the if keyword is used to create conditional statements, allowing your program to make decisions based on certain conditions. The def keyword is used to define functions, and class is used to create classes, a fundamental concept in object-oriented programming.
Help in Python
At times when we are writing out code, we may need help at any stage with some conditional statement, keyword, topic etc. So python has an inbuilt help()
function that can be used anytime.
This help() function can be used in two ways:
1.
First, simply type help() function and then type the topic/keyword in the text box. This type of help is also known as the Interactive help because after calling help() function, the interpreter enters the interactive mode.
2.
Second, in the help function itself, we can pass the topic/keyword using double quotes. For example, help("for").
help("for")
help()
Quick Review
First Python Program | print(“Hello World!”) |
Python Version | import sys print(sys.version) |
Keywords in python | import keyword print(keyword.kwlist) |
Help in Python | help() help(“for”) |
Resources
Questions:
- To use Python as a calculator, we have to write a Program?
- We can use Python —version in the Jupyter Notebook to check the version of Python
- Keywords can be used as the variable names in Python.
- In Python, there is no way to check a list of keywords.
- To cannot check the syntax of any statement in Python without the internet.
Answers:
- False.
- False – It will not work in Jupyter notebook.
- False.
- False, we can check the list of keywords.
- False – we can use the help function.