current position:Home>In Python, what is strip () used for? Is errmsg a keyword or a function? What is it used for

In Python, what is strip () used for? Is errmsg a keyword or a function? What is it used for

2022-02-03 01:30:12 CSDN Q & A

The phenomenon and background of the problem

python in ,strip() What to do ,errmsg Is it a keyword or a function , What to do , Code while I can't understand part of it , Can you explain the meaning of code execution , In the code fieldName and fieldValues Whether it is a keyword parameter

import easygui as egfieldName = ["* user name ","* Real name ","* Phone number ","* email "]fieldValues = []fieldValues = eg.multenterbox(" Please fill in the following contact information :"," Account Center ",fieldName)while 1:    if fieldValues == None:        break    errmsg = ""    for i in range(len(fieldName)):        option = fieldName[i].strip()        if fieldValues[i].strip() == "" and option[0] == "*":            errmsg += ('【%s】 Is required .\n\n' % fieldName[i] )    if errmsg == "":        break    fieldValues = eg.multenterbox(errrmsg," Entry form ",fieldValues)print(" The user information is as follows :%s" % str(fieldValues))
Operation results and error reporting contents
My solution ideas and tried methods
What I want to achieve

Refer to the answer 1:

strip() What to do
answer : Used to delete spaces on both sides

Refer to the answer 2:

Refer to the answer 3:

strip Used to delete the beginning 、 Ending character , similar C# In the language trim function
strip Functions can take arguments , Like writing a.strip(b), Then put the a The beginning and end contain strings b Delete all parts of ( Repeated for many times will also be deleted )
If you don't fill in the parameters , Default is space
errmsg Is a custom variable , As the name suggests, it is error message Well
fieldName and fieldValues Are two custom lists
These are my own names , Not a keyword
You have to get used to python There is no need to write type to define variables in , Direct variable name = Even if the expression is defined

Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.

Random recommended