Basic Notes for Python beginners

Enter multiple arguments in one line of code

Method 1.) a,b,c=map(type,input(” please input “).split()) # default space separation, to convert to other types, change the type to the desired

Such as —– to ** integer **:map(int,input(” please input “).split())
A, b, c = map (int, input (" please enter "). The split ()) print (a + b + c, type (a), type (b), type (c)) # extension: >> please enter 1 2 3 >>>> 6 <class 'int'> <class 'int'> <class 'int'>Copy the code
Such as —– to ** string **:map(STR,input(” please enter “).split())
A, b, c = map (STR, input (" please enter "). The split ()) print (a + b + c, type (a), type (b), type (c)) # extension: >>> enter 123 >>> 123 <class 'STR '> <class' STR '> <class 'STR '>Copy the code

A,b,c=eval(input(” please input “)) a,b,c=eval(input(” please input “)

A, b, c = eval (input (" please enter ")) print (a, b, c, type (a), type (b), type (c)) print (a + b, c, type (a), type (b), type (c)) # extension: When is a string, the string is added, then the '+' sign is concatenated. <class 'int'> <class 'int'> <class 'STR '> >>> 3 Hello <class 'int'> <class 'int'> <class 'str'> 12345678910Copy the code
Convert to string STR
A, b, c = eval (input (" please enter ")) a = STR b = STR (a) (b) print (a + b, c, type (a), type (b), type (c)) # extension: When is a string, the string is added, then the '+' sign is concatenated. >>> enter 1,2,' hello '> >> 12 hello <class 'STR '> <class' STR '> <class 'STR '> 123456789Copy the code

Method 3.) a,b,c=input(” please input “).split(“, “) #split(“, “) #split(“, “) #split(“,”

A, b = input (' enter '). The split (', ') print (a, b, type (a), type (b)) print (a + b, type (a), type (b)) # extension: When is a string, the string is added, then the '+' sign is concatenated. >>> Enter 1,2 <class 'STR '> <class' STR '> >>> 12 <class 'STR '> <class' STR '> 1234567891011Copy the code
Converts to an integer int
A, b = input (' enter '). The split (', ') a = int (a) b = int (b) print (a + b, type (a), type (b)) # extension: >>> enter 1,2 >>> 3 <class 'int'> <class 'int'>Copy the code

The complete project code can be obtained here!