Python basic syntax

Source: Internet
Author: User

1. First learn to use Python to write a+b programs:

A, b = map (int, raw_input (). Split ()) print a+bprint ' \ n '

The Raw_input () function reads a line from the standard input and returns a string (minus the end of the newline character). After reading, the string has a split () function that can be disassembled into a list of substrings based on the delimiter. For objects within a list, you need to take a transform, preserving the continuation of the string. If it is Python3, replace raw_input () with input ().

A, B = raw_input (). Strip (). Split ()

This line of code reads a line of string and separates A, B, but a, B is a string and needs to be converted again to int type. The Strip () method removes the character specified by the string's Kinsoku (the default is a space). Removes only the characters specified by the beginning and ends of the string, and the middle part is not removed.

The following example shows how the strip () function is used:

#!/usr/bin/python="0000000this is string EXAMPLE....WOW!!! 0000000 ";  Print str.  Strip(' 0 ');         

The result of the above example output is as follows:

This isstring example .... WOW!!!

A, B, c = (int (x) for x in Raw_input (). Split ("))

This is a lot of writing algorithms for the classmate, although not how to use Python, but still have OJ Web site to provide support for Python compiler. This notation A, B, C has become an int type, and then the direct numerical operation is done.

Python basic syntax

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.