In our previous article, we learned about How to create a development environment with Windows10, Mac or Linux (Ubuntu). In this article, we are going to write our first python program. In our first Python program, we are going to print "Hello, vLemonn" and "Hello, Python".
For our first example, we are going to open the command prompt.
Following are the steps to display "Hello, vLemonn" using the command line.
1. Open Windows Command Prompt: Press Windows+R and type cmd and then press enter.
2. In command prompt enter Python and then enter. Now you are in Python Command Line Environment. This command line environment is also known as Read–Eval–Print Loop (REPL). What do you mean by REPL? First, have a look at Python command line tool.
In the above image we have ">>>" triple arrows. It means python is waiting for your inputs. If you are going to enter any command python first going to read it, evaluate it, print the final output and then again going to wait for more commands. For more understanding let's run our first command. Type "print("Hello, vLemonn")" and then press enter. And now check below image
As shown in the above image. We entered "print("Hello, vLemonn")". Python print Hello, vLemonn and again waiting for our input.
In our next example, we are going to create a file and use it in Python Command Line. I am assuming our file is available at C:\Tutorial\Python\HelloPython.py. In our HelloPython.py file we have a single line "python ("Hello, Python")".
Now, use "exec(open("C:\Tutorial\Python\HelloPython.py").read())" to check the output for HelloPython.py file. If you are not in Python Command Line then you can use Command prompt command "python "C:\Tutorial\Python\HelloPython.py"" for the same result.
Finally, we are done with command lines. For closing, Python commands line tool press ctrl+z and then enter. For Mac and Linux users press ctrl+d and then enter.
Now it's time to use PyCharm. For launching PyCharm in Windows 10, press windows -> Jet Brains -> JetBrains PyCharm Community Edition.
Create a new project.
Select Project Location and Base Interpreter.
Finally, click on create.
Finally, click on create.
Once the project is created create a new Python file named it Hello. Add following lines
Save your file. For executing Click on Run -> Run "Hello" (Keyboard shortcut Shift+F10).
Following is the output for above execution.
"C:\Users\Mayank Sanghvi\PycharmProjects\Blog\Python36Tutorial\venv\Scripts\python.exe" "C:/Users/Mayank Sanghvi/PycharmProjects/Blog/Python36Tutorial/Hello.py"
Process finished with exit code 0
For the completeness of this article following are command line images from Mac and Linux.
Finally, we reached the end of this article. In our next article, we are going to learn about the Python Data Types.
Please login to post your valuable comments.