Python Learning DAY3 (function input & print)

Source: Internet
Author: User

Input

1 format:

Input ([prompt]) prompt for cue information ctrl + Z end input

2 function functions:

Accepts a standard input data, returns a string type

3 Examples:

  

Print

1 format:

  print ([object, ...], *, sep= ', end= ' \ n ', file=sys.stdout) (end default value is carriage return, customizable symbol)

2 function functions:

Output various types of data: String, Integer, floating-point, perceive, and precision control

3 Examples:

    • Print (): Output a blank line
    • Print (str or number): Direct output of a string or numeric
    • Parameter formatted output
      • #%x---hex hex
      • #%d---Dec decimal
      • #%o---Oct octal
      • #%s---String
      • #%f---float floating point
        • Example 1:
        • STR1 = "The value is:"
        • Number1 = 11
        • Print ("%s%d"% (str1,number1)) #输出 "The value is:11"

        • Example 2:
        • pi=3.1415926
        • Print ("PI =%10.3f"% math.pi) #输出PI = 3.142
        • Print ("PI =%-10.3f"% math.pi) #输出PI = 3.142
        • Example 3:
        • Print ("%.3s"% ("ABCDE")) #输出abc
        • Print ("%.*s"% (4, "ABCDE")) #输出abcd
        • Print ("%10.3s"% ("ABCDE") #输出ABC (total length is 10, character length is not sufficient in front of the blanks)

        • Example 4: Printing multiple lines
        • Print ("Your Content" ") or print (" Your content ")
        • Example 5: Print plain text with no escape character: print (R ' content ') or print (R ' content ')
        • Print (R ' abc\n ') #直接打印字符串abc \ n

  

Python Learning DAY3 (function input & print)

Related Article

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.