Learn basic things before learning conditions, loops, and other statements.
1.print output comma
More information on >>> #print and import
>>> #使用逗号输出
>>> print ' age ', 42
Age 42
>>>
(1, 2, 3)
>>> print (+/-)
(1, 2, 3)
>>> Print
1 2 3
>>> Print 1 2 3
Syntaxerror:invalid syntax
>>> name= ' CHR '
>>> age=42
>>> Print Name,age
CHR 42
>>> print name+ ', ' +age
Traceback (most recent):
File "<pyshell#10>", line 1, in <module>
Print name+ ', ' +age
Typeerror:cannot concatenate ' str ' and ' int ' objects
>>> print name, ', ', age
CHR, 42//Obviously output in this way will increase the space
>>>
Confirm that all features of a package are imported
Import Package *
2, some tips:
······ Multiple assignment operations can be performed simultaneously
>>> x,y,z=1,2,3
>>> print x, Y, Z
1 2 3
······ Exchange values for two variables
>>> x,y=y,x
>>> print x, Y, Z
2 1 3
In fact, these two operations are sequence unpacking.
>>> values=1,2,3
>>> values
(1, 2, 3)
>>> x,y,z=values //Note the number of assignments for both groups should be uniform. Otherwise, an exception is thrown
>>> print x, Y, Z
1 2 3
A simple method of Popitem
>>> hooby={' peo1 ': ' Basketball ', ' Peo2 ': ' runing ', ' peo3 ': ' Shopping '}
>>> Key.value=hooby.popitem () //The error between key and value is written here. Cause assignment errors when corrected again , you will not get the first set of data in the dictionary.
Traceback (most recent):
File "<pyshell#32>", line 1, in <module>
Key.value=hooby.popitem ()
Nameerror:name ' key ' is not defined
>>> Key,value=hooby.popitem ()
>>> Print Key,value
Peo2 runing
>>>
The following is the result of a second call to the first set of data in the dictionary, indicating that the results are correct.
>>> myhooby={' peo1 ': ' Basketball ', ' Peo2 ': ' runing ', ' peo3 ': ' Shopping '}
>>> Key1,value1=myhooby.popitem ()
>>> Print Key1,value1
Peo1 Basketball
For chained assignments and incremental assignments, similar to the C language, except that Python can also target strings, and C does not.
Continue tomorrow conditional and conditional statements.
The fifth lesson of the basic Python tutorial 0121