Efficiency good low today (I love butt, whatever the outcome today after all the gold climb hhh)
To sum up what it learned today
+ |
plus |
- |
Less |
* |
Multiply |
/ |
except |
// |
Divisible (take quotient) |
% |
Remainder |
** |
Index (X = X ** Y Y ) |
1, it can be used to connect the plurality of strings +
2、
% S indicates the character string,
% D represents an integer before the integer spaces can be written as% 5d% 123 will be denoted by "123" accounted for five character positions
% F% 4.2f floating point format to a format, the total length of 4, 2 represents two decimal places
3、
1 a='This is {0:s} {1:d}st python program.'.format ('Max', 1) 2 3 print(a)
4. List
userAge=[21,22,23,24,25] A = userAge [0] # remove the 0-th element B = userAge [2:. 4] # removed [2,4) always left and right open and closed C = userAge [. 1:. 5: 2] # removed [1,5) step 2 # Modify elements directly userAge [ . 1] =. 5 d=userAge # Add the last element using the append () function userAge.append ( 99 ) e=userAge # Remove elements del userAge[2] f=userAge print(a) print(b) print(c) print(d) print (e) print(f)
5-tuple
But much like the list with () do not []. Also you can not modify the value tuples
6, dictionary
use{}
= {userNameAndAge " Peter " : 38 is, " Max " : 18 is, " the Dell " :}. 19 # dict may or may not declare Dictionary #写成userNameAndAge=dict(Peter=38,Max=18,Dell=19) a=userNameAndAge["Peter"] print(a) userNameAndAge [ " Peter " ] = 39 # modify dictionary del userNameAndAge [ " Peter " ] # Delete Peter option
7, interactive program: Input, print
myName=input("Please enter ur name") print("Hello World, my name is ",myName)
8, multi-line expansion: Three quotes
print('''Hello World My name is Max and I love Dell. ''')
9, escaped
\ N print a new line
\ T Tab
10, if conditions
①If condition 1 is met:
do A
elif #else if condition 2 is met:
do B
Relying tab python program to determine the starting position
②do Task A if condition is true else do Task
eg
num1=12 if myInt==10 else 13
11, for circulation
= Qucik Facts Pets [ ' CATS ' , ' Dogs ' , ' Rabbits ' ] for index, myPets in the enumerate (Qucik Facts Pets): # the enumerate to display the index values in the list && do not forget: this stuff Print (index, myPets)
12, while cycling
While condition is true:
do A
eg
counter=5 while counter>0: print("Counter = ", counter) counter=counter-1
Break usage will not go
Continue keyword after the procedure will be skipped in this cycle
j=0 for i in range(5): j=j+2 print('\ni = ', i, ', j = ', j) if j==6: continue print('I will be skipped over if j=6')
13、try &except
try :
do something
except:
do something else when an error occurs.
try: answer =12/0 print(answer) except: print("An error occured")