Python (i)

Source: Internet
Author: User

A. Hello World program

Create a python file in Pycharm

Run results

Rules for variable definitions:

    • Variable names can only be any combination of letters, numbers, or underscores
    • The first character of a variable name cannot be a number
    • The following keywords cannot be declared as variable names
      [' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' F ' Rom ', ' Global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' try ', ' while ', ' WI Th ', ' yield ']

Assigning values to variables

Note: in Python3. UFT-8 encoding is supported directly in X without the need to start labeling in the file. In addition, Chinese variables are supported in Python3

Comments:

When line comment: # is commented content

Multi-line Comment: ' Annotated content '

About single and double quotation marks:

Single and double quotes in Python are not removed, quotation marks can be applied in quotation marks without causing errors

About three quotes:

13 quotation marks for multi-line comments

23 quotation marks can represent multi-line content, formatted output of multi-line content

1.

2.

3.

Note: Not recommended method Three, method three need to strictly remember the variable order

User input:

Note: input is a string type and must be cast with an int () If you need to reshape the value. You can also cast to a string using str ().

If you do not want to enter the password visible, you can use the Getpass method in the Getpass module:

SELECT statement:

If...else

If...elif...else

Loop structure:

1.for Loop:

2while Loop:

Python (i)

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.