Python knowledge Miscellany

Input array separated by spaces

  1. Input array separated by spaces, using split function strings may be separated by a space, e.g. dir = input (). Split ( ''), to obtain an array dir
  2. However, this string is stored as an array, so in this case, we can use the map function, for example: dir = map (int, input () split ( '').) To obtain an array of int.
  3. Alternatively, if a known number of variables to store, can be assigned directly Example: ch1, ch2, ch3 = map (int, input.split ( ''), but this time the number of digits to be entered and left the number of variables consistency

Python how to set an EOF stop cycle 

Use try :. . . except: the input statement block wrap, when an EOF exception performed except block.

E.g:

while True:
    try:
        x1,y1,x2,y2=map(int,input().split())
    except:
        break

Miscellany:

Python is not increment operator, it can use a similar manner as + 1 =

expected an indented block: indentation error

 

Published 42 original articles · won praise 16 · views 3410

Guess you like

Origin blog.csdn.net/qq_41542638/article/details/96010961