First knowledge of Python

Source: Internet
Author: User

Python Basics (i): Operators: Arithmetic operations:

In addition to the basic +-*/, you need to know://To take the integer portion of the returned market quotient for example: 9//2---> 4, 9.0//2.0--->4.0

% is the remainder of the division returned by the remainder is 0 for example: 3 3---> 0, Surplus: 6 3--->2

Logical operators:

And, or, not

Comparison operators:

= = Determines whether two numbers are equal,! = Determines whether two numbers are unequal, >, <, >=, <=

Member operators:

        

List_1 =[1,2,3,4,5]

In:

1 in list_1---> True
Not in:

6 in list_1---> False

Format character. Format (): Control accuracy:

PI = 3.1415926
Print ("PI is accurate to 3 digits after decimal point: {0:.3f}". Format (PI))
Pi is accurate to 3 digits after the decimal point: 3.142

Padding characters:

W_1 = "word"

"{0:-^30}". Format (w_1)---> '-------------word-------------'

If judgment and while for loop:

While loops generally determine the condition of a loop by whether the value is satisfied

A For loop is typically a pair of variables that can hold multiple data and traverse

List_2 = [1,2,3,4,5,66] for in list_2:    print(i)

Multiplication table ()

i = 0 while I <=9:    = 1 while     m <= i:        print(  '%d*%d=%d'% (m,i,m*i), end=')        +=1     Print(")    i+=1

Scissors

1 ImportRandom2 3Player = input ('Please enter: Scissors (0) stone (1) cloth (2):')4 5Player =Int (player)6 7Computer = Random.randint (0,2)8 9     if(player = = 0) and(Computer = = 2))or((Player ==1) and(computer = = 0))or(player = = 2) and(Computer = = 1)):Ten         Print('win, Haha, you're so awesome.') One     elifPlayer = =Computer: A         Print('a draw, or another inning.') -     Else: -         Print('lose, do not go, wash your hands and then come, the battle till Dawn')
Break and Continue

The function of break: To end the entire cycle

  Continue: Used to end the cycle, followed by the next cycle

First knowledge of Python

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.