Python Basics "One"

Source: Internet
Author: User

Reasons to like Python:

The reason for liking Python is that Python is too handy to write. And like its modular programming program;

Python installation, and development environment:

Can be downloaded in their official website, I downloaded the comparison earlier, With a version of 2.73, the path path of Python is configured in the computer's properties, and the development environment is casual, you can write Python code using Notepad or another editor, run it under CMD, or use the python's own idle code.

Python's first program HelloWorld:

we create a. py file anywhere on the computer. Write a line of code inside the file

print ' HelloWorld ' to save this file

How to run it: You can find the path to run the. Py under CMD, or you can choose to open it and find Python idle to run the file.

Python's Modular Authoring:

Python's modular writing it's cool; you can divide a feature's implementation into multiple modules, put them in a Python file, and connect them together, and it's straightforward. Write an example;

I want to implement an addition and a subtraction function, and then call them;

First I create a folder called SRC. I wrote the. py file for my implementation of additions in the sums.py

Def _sum (A, B)

Sum=a+b

return sum

I'm creating a subtraction. py file subs.py

Def _sub (A, B)

Sub=a-b

Return Sub

Below we create a. py file to invoke the above method; Create a result.py file

Next we import the module:

In the result.py file, write the following code:

A= __import__ (' sums ')
b = __import__ (' subs ')

C=a._sum (10,20)

D=b._sub (20,10)

Print C

Print D

Run result.py, you can get the results, it is not very clear;

We can not use any editor, just download a Python interpreter, understand the Python language indentation style, you can easily write a Python program;

Python Basics "One"

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.