Python 01, python01

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.