Python basic syntax

Source: Internet
Author: User

1. Print

Print as function in 3.x

Print ("1", "2") i.e. Output 1 2

2.x print is not a function, so

Print "1", "2" i.e. output 1 2

2. Input and Raw_inputraw_input

Raw_input () treats all input as a string and returns the string type. As a gets ()

Like what:

gender = Raw_input ("what' s your gender? ") " )print(gender) Input: Male output: Male'str'>

Input

Input () under the 3.x version:

Input () is equivalent to eval (raw_input (prompt)) when inputs are not for shaping and floating point types

Where eval evaluates the string str as a valid expression and returns the result of the calculation. Like what:

string conversion to list " [ [up], [3,4], [5,6], [7,8], [9,0]] ">>>type (a)'str'>>>> b = eval (a)  Print  b[[1, 2], [3, 4], [5, 6], [7, 8], [9, 0]]>>> type (b)'
   
    list
    '>
   

If the input is an integer or a floating-point number, it is returned directly. can be used as input, output template input.

As follows:

c = input ("pleaseinput number")print  cprint  type (c)
Input: 2.31
Result:'float'>

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.