Home > other >  Python final review summary
Python final review summary

Time:10-05

1. Def shun (x) :
X=x * 2
Return the x
A=[7, 1]
B=shun (a)
Print (a, b)
# define functions shun make x=x * 2 that is, the return value is repeated input worth twice, but first should output over the input values, the result for (7, 1], [7,1,7,1]
2. Def func (=22 a, b, c=33) :
Print (a, b, c)
Func (9101)
Def func (a, b, * p) :
Print (p)
Func (9, 0, 2, 4, 6)
# for the first time the output value of 22,22,33 output after 9101 0 33
3. Def demo () :
Global x
X=56
Return None
X=196
The demo ()
Print (x)
# because of the global function and position before setting function value so that the output of 56
4. X='YiBingDing armour YiBingJia b
Y=x.i ndex (' a ') + x.c mount (' a ')
Print (y)
# test whether x the armour as a string, or 0 x number of armour to output 3 add the final result is 3
5. String STR's built-in method. The split (),
What type of data is its return value?
Answer: STR, list, tuple, dict
X='It \ nis WWW. The split ()
Y='+'. Join (x)
Print (y)
# with a whitespace-delimited integer elements, finally get should be a list, select a list
6. S='huangyanhui'
Y=(s) in 'yellow' + 'yan' (s) in the
Print (y)
# test whether huang in s, n is 0 test for a in s, yan has the output 1 combined output 1
7. S='A1B2C3D4'
[2] : : s=s + s [: : - 2]
Print (s)
# take a positive start every two elements, then take an element from the negative to begin each two finally together output ABCD4321
8. N=837.7170721880799
S='{0:08. 2 f} - {0:. 2 g}'. The format (n)
Print (n)
# 8 position the rest with 0 only keep two decimal places, the output of 00837.72-8.4 e+02
9. The for c in 'Hello World' :
If c=='o:
The continue
Print (c, end=' ')
# traversal cycle, meet o continue to cycle after the jump finally output Hell WRLD
10. For I in range (1, 6) :
If I % 4==0:
Break
Print (I, end=', ')
1-5 # traversal cycle if a number is divided by four remainder is 0 stop cycle, so the final output 1, 2, 3
11. Complete code #, calculate and tan (x)
The import math
X=math. PI/4
Y=the...
# introduction module math.h calculation of PI to tan () also need to introduce tan so fill math.h tan (x)
# 12. Run the following code, input from the keyboard 123
X=eval (input ())
Print (x * 2)
# eval function specifies if the digital output value is equal to the output value multiplied two so output 246
13. Print (1912, 510, 4501, sep='+'
Output # 1912 + 510 + 4501
14.2 * * 2//2
# 8 * * said output index//said in addition to the integer part after
15. X=39
//x=3
Print (x)
# 13 output

CodePudding user response:

Brother come on! The exam!
  • Related