Next day Python input, if statement, etc.

Source: Internet
Author: User

Action: Mouse can drag code and comments

Print No Line break
Print ("Hello, end="----")
Print ("Luhan, end="----"")
Print (i,end= "--")

\ n Plus string in front

String% variable formatted output

names = "Luhan"
Print ("Name is:%s"%names)

multiple outputs ()

edu = "Undergraduate"
Address = "Shunyi"
Print ("Education is:%s live in%s"% (edu,address))

%5D%05d-occupied
Student_no = 1
Print ("study number is%5d"%student_no) #占5位
Print ("study number is%05d"%student_no) #占5位, preceded by the

%.3F Reserved Decimals
Price = 30.666
Print ("Price is:%.3f"%price) # Default 6-bit decimal%.3f is a shorthand for%0.3f, reserved three decimal places

% OUTPUT%
Scale = 10
Print ("Scale of data is%.2f%%"%scale)

Input inputs: input (hint information) is typed in string type

Conversion: Int (variable) float (variable) str (variable)

String decimals cannot be converted to integral type
b = "12.33" b = int (b) Error
Floating-point type can be converted to integral type
b = 12.33 B = Int (b) No problem

Two number swaps
A = 10
b = 20
A, B = b,a

Power to fetch quotient

Python xor, bitwise, and

Priority: () > Arithmetic > Compare > Logic > Assignment + = 、...、%=,//= calculation assignment
result = 3 * 5 > 4-2 < 1

If statement judgment, two number comparison without float type float

If, if else, if elif if

Random number generation
Import Random
n = random.randint (0,2) # [0,2] 0-2 generate random number

Next day Python input, if statement, etc.

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.