First, Function Import
1. Provide aliases for the module
>>> Import Math as Foobar #设置math alias Foobar
>>> Foobar.sqrt (4)
Showing: 2.0
2. Provide aliases for functions
>>> from math import sqrt as Foobar
>>> Foobar (4)
Showing: 2.0
Second, assign the value
1, multi-value assignment
>>> x,y,z=1,2,3
>>> print (x, y, z)
Show:
2, multi-value exchange
>>> x,y=y,x
>>> print (x, y, z)
Display: 2,1,3
3. Increment Assignment
>>> x=2
>>> x+=1
>>> x*=2
>>> x
Showing: 6
Iii. conditional execution and if statements
1. If nesting code
>>> Name=input (' What's your name? ‘)
>>> if Name.endswith (' Gumby '):
>>> if Name.startswith (' Mr. '):
>>> print (' Hello, Mr Gumby ')
>>> elif name.startswith (' Mrs. ')
>>> print (' Hello, Mrs. Gumby ')
>>> Else:
>>> print (' Hello, Gumby ')
>>> Else:
>>> print (' Hello,stranger ')
2, is, the identity operator, and = = are similar, but in fact not the same
>>> x=y=[1,2,3]
>>> z=[1,2,3]
>>> x==y
Display: True
>>> x==z
Display: True
>>> x is y
Display: True
>>> X is Z
Display: False
3, in, membership operator
>>> if ' s ' in Name:
>>> print (' Your name contains the letter "s")
>>> Else:
>>> print (' Your name does not contain ' s '. ')
4. Assert, Assert
>>>age=-1
>>> assert 0<age<100, ' the must be realistic '
Showing: assertionerror:the must be realistic
5. While loop
>>> x=1
>>> while x<= 100:
>>> Print (x)
>>> x+=1
6. For loop
>>> numbers=[0,1,2,3,4,5,6,7]
>>> for number in numbers:
>>> Print (number)
Python learning notes conditions, loops, and other statements