Python 01, python01
1. I personally feel that the best tool for writing Python programs is pycharm. The automatic complementing function can satisfy most people who do not like to remember it;
Install the python interpreter before installing pycharm. Currently, the latest Python version is 3.5 (you can download it directly on www.python.org)
2. The first program (helloword ):
If anyone who has learned Java knows that writing a helloword program requires defining classes and main methods. This is especially troublesome. Let's take a look at it, in Python, if a simple output is implemented:
Print ('helloword !! ') => Helloword
It's a simple output (Note: if it is executed in Linux, add # In the first line #! /Usr/bin/env python interpreter path. If the output contains Chinese characters,
You also need to convert to UTF-8 output (#:-*-coding: UTF-8 -*-))
Iii. Use of if/else, while, and:
All users who have learned about Linux know that these conditions are often used to write shell scripts in Linux. The following is a comparison between shell and Python:
<1> in Linux, if/else is like this:
If [1-gt 2]; then
Echo "fail !! "
Else
Echo "OK !! "
Fi
<2> in Python, it is as follows:
If 1> 2:
Print ('fail !! ')
Else:
Print ('OK ')
Summary: Although there are just a few lines of code, it can be seen that the Python script is relatively simple. In addition to indentation, other scripts are not prone to errors, there are several differences:
1. Python requires strict indentation. By default, four spaces are indented in pycharm. Linux does not have high requirements on indentation.
2. linux has a strict ending mark, but Python does not need it. This saves multiple lines of code.
3. The end of each condition statement is:, while and for are the same.