Humans use various languages to communicate to each other.
Whereas Computers understand only Machine Language/Computer Language of 1s and 0s.
We write code using various Programming Languages like C, C++, C#, PHP, Java, Python etc.
Higher Level Languages: Programming Languages closer to languages humans use are Higher Level Languages.
Lower Level Languages: Programming Languages closer to language computers understand i.e. 0s and 1s are Lower Level Languages.
Translators are used to convert code written in Programming Language (source code) into Machine Language/Computer Language:
Translators can be:
Interpreters (Execution is done line by line)
or
Compilers (Whole code is executed in one go)
What isPython?
Python is a very popular, widely-used, and easy to learn programming language.
Python is a general-purpose programming language.
It is used everywhere, some of the important fields where Python is used are:
Data Science
Machine Learning
Artificial Intelligence
Web Development
Mobile App Development
Game Development
and a lot more…
It supports a variety of paradigms for programming, including structured programming, object-oriented programming, and functional programming.
Python was created in 1989 by Guido van Rossum.
The name Python doesn’t refer to the snake. Apparently, Guido van Rossum was a big fan of Monty Python’s Flying Circus, a TV series by a well-known comedy group from Britain, and he named the language after them.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
All these languages involve many brackets, parentheses, and semicolons, and many words with meanings that are not immediately obvious.
Using Python writing the same code is very easy as you can see for yourself:
Python
print('Hello World!')
Creatinga Python file
So far you have written code into the Shell.
The Shell is not an appropriate place for writing large programs.
Python, like every other computer language, allows you to put the code you write into a file, save it, open it at any time and run it without having to retype it.
To create a new file in IDLE, you go to the File menu and select New File or use the keyboard shortcut Control+N in Windows.
This opens a new, blank editing window, waiting for you to enter Python code.
You enter your line of Python code in this editing window.
To move to next line you press enter at the end of a line and in this manner you enter your Python code, line by line.
Let’s build a simple program containing three print statements.
Notice that when you open the file, it is named Untitled in the window title.
Enter the following:
print('I am now entering Python code into a Python file.')
print('When I press Return or Enter here, I move to next line.')
print('This is the last line.')
Notice that when you started typing, the window title changed to *Untitled*.
Savinga Python file
To save the file, click File menu and then click Save.
Alternatively, press the standard Control+S (Windows) or Command+S (Mac).
Enter the name of the file say “Test”.
However, Python filenames should always end with a .py extension.
Therefore, you should enter the name “Test.py” in the Save As dialog box.
The code you write is platform independent.
If you create a Python file on one platform, you can move that file to another platform and it will open and run just fine.
Runninga Python file
To run, or execute, the statements in the file, click Run ➤ Run Module or press the F5 shortcut key.
If you don’t save the file before you try to run it, IDLE will prompt you by asking you to save the file.
Each time you make changes and you want to test the new code, you must save the file and then run it.
If everything went well, the program should print the following in the Shell:
I am now entering Python code into a Python file.
When I press Return or Enter here, I move to next line.
This is the last line.
After giving the output the Shell will display the prompt >>>
QuitIDLE
Now let’s quit IDLE by clicking click File ➤ Exit (Windows) or IDLE ➤ Quit IDLE (Mac).
Alternatively, you can press Control+Q (Windows) or Command+Q (Mac) keys.
Openinga previously saved Python file
To open a previously saved python file first open IDLE.
Then you can click File ➤ Open and navigate to the file you want to open.
Alternatively browse to the saved Python file using windows explorer and then right-click the file icon.
From the context menu that appears, select the second item, Edit with IDLE.