DEV Community

Cover image for Learn Python - 1. Start with python🥳
Phoenix
Phoenix

Posted on

Learn Python - 1. Start with python🥳

Install Python

Python is installed by default on Mac and Linux operating systems. To check if Python is installed on Windows, first open cmd and type the following command in it: C: \ Users \ Your Name> python –version

For Mac and Linux, type the above command on the command line or terminal. If Python is not installed on your computer, you can download it from python.org.

Running Python Programs

As mentioned earlier, Python is an interpretive programming language. This means that you, as a developer, write Python (py.) Files in a text editor or development environment (IDE) such as Eclipse and execute them with the Python interpreter.

The following command in the command line executes a python file called helloworld.py:

C:\Users\Your Name>python helloworld.py

Let's write our first program in a Python file called helloworld.py

print("Hello, World!")

To run the program, just run the above command line command. The output is as follows:

Hello, World!

congratulation! You wrote your first program in Python🥳🥳

Python Command Line

To test shortcodes, you can write them on the command line to a file. This method is easier and faster. Open the operating system command line and type and run the phrase python. There you can write any program by Python:

`C:\Users\Your Name>python
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

print(“Hello, World!”)`


Which prints the phrase inside the quotation mark in the same place. You can use exit () to exit the Python command line.

Structure of Python Commands

Indentations in Python

While Tab is used for readability in programming languages, this is a must in Python. Python uses indentations to specify blocks of code:

if 5 > 2:
print("Five is greater than two!")

If you run the following commands, Python will give an error:

if 5 > 2:
print("Five is greater than two!")

Comments Descriptions are used to explain part of the code and document the code. Comments start with a footnote and continue to the end of the same line:

#This is a comment.
print("Hello, World!")

Python has also developed a documentation feature called docstrings. docstrings can contain one or more lines. The docstring begins and ends with three quotation marks:

"""This is a
multiline docstring."""
print("Hello, World!")

The start-up session with Python is over. In the next session, we will teach variables in Python.

Do not forget to like!
Bye until the next post👋

Top comments (0)