article ARTICLE
article3 min read

How to use a source code file? The first Python script

Whenever we learn a new programming language, the first program we write and run to be “Hello,World!”. All it does is to say “Hello World” when we run it. As Simon Cozens pinpointed it is the traditional spell to programming gods to help us learnthe programming language better”.
So, to display the"Welcome to Python world!" message in our first script, we should open the Python GUI. Then, we should choose File → New Window or press Ctrl + N and enter the print ("Welcome to Python world") program.  Next, to that we select File → Save or Ctrl +S and save it as welcometopython.py. Then, while staying in the code window, we should select Run module and press F5.
We can also run this program by opening a shell (Linux terminal or command line in DOS) and importing the Python 3.3.2 welcometopython.py command. Bear in mind that before you give the command to run helloworld.py, you must have moved to the folder where the welocometopython.py file is stored. After that, some remarkable remarks are worthwhile to be mentioned. Python gives you the output of the line directly. What you write is a statement in the Python language. Use the “print” order to get whatever value we provide
Closing the console: To close the console, press ctrl-d (EOF-End Of File symbol) if you use IDLE or a Linux / BSD shell. Respectively, if you use the Windows command prompt, press ctrl-z and then press enter. If you have received an error message, re-write the above program and run it again.
Note that Python is case-sensitive, for example print is not the same as Print. Also, make sure there are no spaces or tabs before the first character (letter) on each line.
Let's stand on the first two lines of the program. These are called comments. So whatever the right # symbol is a comment. Comments are mainly used as notes for the program reader.
Python ignores the comments except for the first line special case. Thisis called the shebang line. Anytime the first two characters of the source file are # followed by the location of a program. This tells the Linux / Unix system that this program should be run with this interpreter when it's time to run.
For example, write:
#!/usr/bin/python3.3
#Filename:welcometopython.py
print ("Welcome to Python world!")
Note that you can always run the program on any platform by specifying the interpreter directly at the command line. For example, if you use Python 3.3.2, press welcometopython.py.
Use comments in your programs to explain some important details of the program. It is very useful for readers of your program so they can easily understand what the program does.
Comments are followed by the Python command. Here, we use the print function that simply prints the text “Welcome to Python world!”. In any case, remember that whatever you enter between parentheses will be printed on the screen





Groups

3
  •  Inspiring
  • comment_icon  Comment