Python Syntax :

First python program :

Python syntax can be executed by writing directly in the Command Line, or by creating a python file on the server, using the .py file extension, and running it in the Command Line.

Directly - Command Line :

  1. Open "DOS/CMD"
  2. type python command (active python language / Enter the python language)
  3. then type print("Hello, World") this code
  4. Hit Enter, Done!
python command line direct

.py file - Command Line :

  1. Open a Text Editor (Recommend: Notepad++)
  2. Write your code on the editor, and save it python installation directory with .py extention (my instalation directory "c:/python", you save it your python installation directory)
    python with notepad++
  3. Open "DOS/CMD" and change your directory. (example: cd: c:/python)
  4. Executable command is : python
  5. Hit Enter, Done!
python server .py extention command line

.py file double click run - Commend Line :

  1. Write scripts and save it with .py extention (Any location/directory/path) and we use: #Hello world! For comments and input("any key to exit...") use for hold the screen after executing the program) :
    python notepad++ direct run
  2. After save just double click the file, Done!
python double click to run

Note : Here we use input() function just for hold the screen after executing the program.

Python Comments :

In python language ( # ) sing use for comments, all characters after the # and up to the end of the physical line are part of the comment and the Python interpreter ignores them.

Example :

  1. #first comment
  2. print("Hello, Python!") #second comment
  3. #third comment

Output :

python comments with exit function

Note : We use print() function for showing some texts/values and exit() function use for exit from the python.

Docstrings / Multiple Line Comments :

Python also has extended documentation capability, called docstrings. Docstrings can be one line, or multiline. Following triple-quoted string is also ignored by Python interpreter and can be used as a multiline comments.

Example :

  1. """
  2. This is a
  3. multiline docstring.
  4. """
  5. print("Hello, python!")
  6. input()

Output :

python docstring comments

Multiple Statements on a Single Line :

The semicolon ( ; ) allows multiple statements on the single line given that neither statement starts a new code block. Here is a sample snip using the semicolon :

Example :

name = 'AyaN'; age='24'; print("My name is: " + name + "\n" + "My age is: " + age); input();

Output :

python semicolon and new line

Note : \n is help you create a new line.

Next Update


Currently, we are working on other servers, but soon we update our website with new content. So, stay tuned we are back soon with new content.

Free Courses