[{"data":1,"prerenderedAt":1617},["ShallowReactive",2],{"doc-\u002Freference\u002Fpython-string-strip-method":3},{"id":4,"title":5,"body":6,"description":1610,"extension":1611,"meta":1612,"navigation":184,"path":1613,"seo":1614,"stem":1615,"__hash__":1616},"content\u002Freference\u002Fpython-string-strip-method.md","Python String strip() Method",{"type":7,"value":8,"toc":1580},"minimark",[9,19,26,29,34,105,108,117,123,130,135,138,159,162,213,215,230,239,247,251,254,266,272,275,309,311,320,325,328,371,373,381,384,398,404,409,412,430,433,483,485,494,497,565,567,576,583,586,643,645,673,682,689,693,699,702,713,715,755,757,765,768,809,811,820,823,848,851,861,873,876,893,895,973,975,1007,1010,1014,1017,1044,1046,1089,1091,1100,1112,1122,1130,1136,1141,1144,1158,1160,1212,1214,1223,1235,1239,1242,1267,1270,1350,1352,1388,1391,1470,1475,1479,1486,1492,1498,1501,1508,1511,1521,1529,1533,1542,1546,1576],[10,11,13,14,18],"h1",{"id":12},"python-string-strip-method","Python String ",[15,16,17],"code",{},"strip()"," Method",[20,21,22,23,25],"p",{},"The Python ",[15,24,17],{}," method removes characters from the beginning and end of a string.",[20,27,28],{},"Beginners usually use it to remove extra whitespace, such as spaces, tabs, and newline characters. This is especially useful when cleaning user input or processing text from a file.",[30,31,33],"h2",{"id":32},"quick-answer","Quick answer",[35,36,41],"pre",{"className":37,"code":38,"language":39,"meta":40,"style":40},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","text = \"  hello  \"\nclean_text = text.strip()\nprint(clean_text)\n","python","",[15,42,43,67,89],{"__ignoreMap":40},[44,45,48,52,56,60,64],"span",{"class":46,"line":47},"line",1,[44,49,51],{"class":50},"su5hD","text ",[44,53,55],{"class":54},"smGrS","=",[44,57,59],{"class":58},"sjJ54"," \"",[44,61,63],{"class":62},"s_sjI","  hello  ",[44,65,66],{"class":58},"\"\n",[44,68,70,73,75,78,82,86],{"class":46,"line":69},2,[44,71,72],{"class":50},"clean_text ",[44,74,55],{"class":54},[44,76,77],{"class":50}," text",[44,79,81],{"class":80},"sP7_E",".",[44,83,85],{"class":84},"slqww","strip",[44,87,88],{"class":80},"()\n",[44,90,92,96,99,102],{"class":46,"line":91},3,[44,93,95],{"class":94},"sptTA","print",[44,97,98],{"class":80},"(",[44,100,101],{"class":84},"clean_text",[44,103,104],{"class":80},")\n",[20,106,107],{},"Output:",[35,109,111],{"className":37,"code":110,"language":39,"meta":40,"style":40},"hello\n",[15,112,113],{"__ignoreMap":40},[44,114,115],{"class":46,"line":47},[44,116,110],{"class":50},[20,118,119,120,122],{},"Use ",[15,121,17],{}," to remove whitespace from both ends of a string. It does not change the original string.",[30,124,126,127,129],{"id":125},"what-strip-does","What ",[15,128,17],{}," does",[20,131,132,134],{},[15,133,17],{}," is a string method that returns a new string.",[20,136,137],{},"Key points:",[139,140,141,147,150,153,156],"ul",{},[142,143,144,146],"li",{},[15,145,17],{}," returns a new string",[142,148,149],{},"It removes characters from the beginning and end only",[142,151,152],{},"By default, it removes whitespace",[142,154,155],{},"It does not remove characters from the middle of the string",[142,157,158],{},"Strings are immutable, so the original string stays the same",[20,160,161],{},"Example:",[35,163,165],{"className":37,"code":164,"language":39,"meta":40,"style":40},"text = \"  hello world  \"\n\nprint(text.strip())\nprint(text)\n",[15,166,167,180,186,202],{"__ignoreMap":40},[44,168,169,171,173,175,178],{"class":46,"line":47},[44,170,51],{"class":50},[44,172,55],{"class":54},[44,174,59],{"class":58},[44,176,177],{"class":62},"  hello world  ",[44,179,66],{"class":58},[44,181,182],{"class":46,"line":69},[44,183,185],{"emptyLinePlaceholder":184},true,"\n",[44,187,188,190,192,195,197,199],{"class":46,"line":91},[44,189,95],{"class":94},[44,191,98],{"class":80},[44,193,194],{"class":84},"text",[44,196,81],{"class":80},[44,198,85],{"class":84},[44,200,201],{"class":80},"())\n",[44,203,205,207,209,211],{"class":46,"line":204},4,[44,206,95],{"class":94},[44,208,98],{"class":80},[44,210,194],{"class":84},[44,212,104],{"class":80},[20,214,107],{},[35,216,218],{"className":37,"code":217,"language":39,"meta":40,"style":40},"hello world\n  hello world  \n",[15,219,220,225],{"__ignoreMap":40},[44,221,222],{"class":46,"line":47},[44,223,224],{"class":50},"hello world\n",[44,226,227],{"class":46,"line":69},[44,228,229],{"class":50},"  hello world\n",[20,231,232,233,235,236,238],{},"The cleaned version is returned by ",[15,234,17],{},", but the original ",[15,237,194],{}," value is unchanged.",[20,240,241,242,81],{},"If you are new to strings, see ",[243,244,246],"a",{"href":245},"\u002Flearn\u002Fpython-strings-explained-basics-and-examples\u002F","Python strings explained: basics and examples",[30,248,250],{"id":249},"basic-syntax","Basic syntax",[20,252,253],{},"There are two common forms:",[139,255,256,261],{},[142,257,258],{},[15,259,260],{},"string.strip()",[142,262,263],{},[15,264,265],{},"string.strip(chars)",[267,268,270],"h3",{"id":269},"stringstrip",[15,271,260],{},[20,273,274],{},"This removes whitespace from both ends:",[35,276,278],{"className":37,"code":277,"language":39,"meta":40,"style":40},"name = \"  Alice  \"\nprint(name.strip())\n",[15,279,280,294],{"__ignoreMap":40},[44,281,282,285,287,289,292],{"class":46,"line":47},[44,283,284],{"class":50},"name ",[44,286,55],{"class":54},[44,288,59],{"class":58},[44,290,291],{"class":62},"  Alice  ",[44,293,66],{"class":58},[44,295,296,298,300,303,305,307],{"class":46,"line":69},[44,297,95],{"class":94},[44,299,98],{"class":80},[44,301,302],{"class":84},"name",[44,304,81],{"class":80},[44,306,85],{"class":84},[44,308,201],{"class":80},[20,310,107],{},[35,312,314],{"className":37,"code":313,"language":39,"meta":40,"style":40},"Alice\n",[15,315,316],{"__ignoreMap":40},[44,317,318],{"class":46,"line":47},[44,319,313],{"class":50},[267,321,323],{"id":322},"stringstripchars",[15,324,265],{},[20,326,327],{},"This removes any matching characters from both ends:",[35,329,331],{"className":37,"code":330,"language":39,"meta":40,"style":40},"text = \"!!hello??\"\nprint(text.strip(\"!?\"))\n",[15,332,333,346],{"__ignoreMap":40},[44,334,335,337,339,341,344],{"class":46,"line":47},[44,336,51],{"class":50},[44,338,55],{"class":54},[44,340,59],{"class":58},[44,342,343],{"class":62},"!!hello??",[44,345,66],{"class":58},[44,347,348,350,352,354,356,358,360,363,366,368],{"class":46,"line":69},[44,349,95],{"class":94},[44,351,98],{"class":80},[44,353,194],{"class":84},[44,355,81],{"class":80},[44,357,85],{"class":84},[44,359,98],{"class":80},[44,361,362],{"class":58},"\"",[44,364,365],{"class":62},"!?",[44,367,362],{"class":58},[44,369,370],{"class":80},"))\n",[20,372,107],{},[35,374,375],{"className":37,"code":110,"language":39,"meta":40,"style":40},[15,376,377],{"__ignoreMap":40},[44,378,379],{"class":46,"line":47},[44,380,110],{"class":50},[20,382,383],{},"Important:",[139,385,386,392],{},[142,387,388,391],{},[15,389,390],{},"chars"," means a set of characters to remove from both ends",[142,393,394,395,397],{},"The order of characters in ",[15,396,390],{}," does not matter",[30,399,401,402],{"id":400},"remove-whitespace-with-strip","Remove whitespace with ",[15,403,17],{},[20,405,406,407,81],{},"This is the most common use of ",[15,408,17],{},[20,410,411],{},"It is useful for:",[139,413,414,421,424,427],{},[142,415,416,417,420],{},"Cleaning ",[15,418,419],{},"input()"," values",[142,422,423],{},"Cleaning lines read from a file",[142,425,426],{},"Removing spaces before checking or comparing text",[142,428,429],{},"Removing tabs and newline characters at both ends",[20,431,432],{},"Example with user input:",[35,434,436],{"className":37,"code":435,"language":39,"meta":40,"style":40},"username = \"  sam  \"\nclean_username = username.strip()\n\nprint(clean_username)\n",[15,437,438,452,468,472],{"__ignoreMap":40},[44,439,440,443,445,447,450],{"class":46,"line":47},[44,441,442],{"class":50},"username ",[44,444,55],{"class":54},[44,446,59],{"class":58},[44,448,449],{"class":62},"  sam  ",[44,451,66],{"class":58},[44,453,454,457,459,462,464,466],{"class":46,"line":69},[44,455,456],{"class":50},"clean_username ",[44,458,55],{"class":54},[44,460,461],{"class":50}," username",[44,463,81],{"class":80},[44,465,85],{"class":84},[44,467,88],{"class":80},[44,469,470],{"class":46,"line":91},[44,471,185],{"emptyLinePlaceholder":184},[44,473,474,476,478,481],{"class":46,"line":204},[44,475,95],{"class":94},[44,477,98],{"class":80},[44,479,480],{"class":84},"clean_username",[44,482,104],{"class":80},[20,484,107],{},[35,486,488],{"className":37,"code":487,"language":39,"meta":40,"style":40},"sam\n",[15,489,490],{"__ignoreMap":40},[44,491,492],{"class":46,"line":47},[44,493,487],{"class":50},[20,495,496],{},"This matters when comparing strings:",[35,498,500],{"className":37,"code":499,"language":39,"meta":40,"style":40},"answer = \" yes  \"\n\nif answer.strip() == \"yes\":\n    print(\"Matched\")\n",[15,501,502,516,520,549],{"__ignoreMap":40},[44,503,504,507,509,511,514],{"class":46,"line":47},[44,505,506],{"class":50},"answer ",[44,508,55],{"class":54},[44,510,59],{"class":58},[44,512,513],{"class":62}," yes  ",[44,515,66],{"class":58},[44,517,518],{"class":46,"line":69},[44,519,185],{"emptyLinePlaceholder":184},[44,521,522,526,529,531,533,536,539,541,544,546],{"class":46,"line":91},[44,523,525],{"class":524},"sVHd0","if",[44,527,528],{"class":50}," answer",[44,530,81],{"class":80},[44,532,85],{"class":84},[44,534,535],{"class":80},"()",[44,537,538],{"class":54}," ==",[44,540,59],{"class":58},[44,542,543],{"class":62},"yes",[44,545,362],{"class":58},[44,547,548],{"class":80},":\n",[44,550,551,554,556,558,561,563],{"class":46,"line":204},[44,552,553],{"class":94},"    print",[44,555,98],{"class":80},[44,557,362],{"class":58},[44,559,560],{"class":62},"Matched",[44,562,362],{"class":58},[44,564,104],{"class":80},[20,566,107],{},[35,568,570],{"className":37,"code":569,"language":39,"meta":40,"style":40},"Matched\n",[15,571,572],{"__ignoreMap":40},[44,573,574],{"class":46,"line":47},[44,575,569],{"class":50},[20,577,578,579,81],{},"If you want a broader guide, see ",[243,580,582],{"href":581},"\u002Fhow-to\u002Fhow-to-remove-whitespace-from-a-string-in-python\u002F","how to remove whitespace from a string in Python",[20,584,585],{},"Example with file-style text:",[35,587,589],{"className":37,"code":588,"language":39,"meta":40,"style":40},"line = \"Python basics\\n\"\nprint(repr(line))\nprint(repr(line.strip()))\n",[15,590,591,609,624],{"__ignoreMap":40},[44,592,593,596,598,600,603,607],{"class":46,"line":47},[44,594,595],{"class":50},"line ",[44,597,55],{"class":54},[44,599,59],{"class":58},[44,601,602],{"class":62},"Python basics",[44,604,606],{"class":605},"s_hVV","\\n",[44,608,66],{"class":58},[44,610,611,613,615,618,620,622],{"class":46,"line":69},[44,612,95],{"class":94},[44,614,98],{"class":80},[44,616,617],{"class":94},"repr",[44,619,98],{"class":80},[44,621,46],{"class":84},[44,623,370],{"class":80},[44,625,626,628,630,632,634,636,638,640],{"class":46,"line":91},[44,627,95],{"class":94},[44,629,98],{"class":80},[44,631,617],{"class":94},[44,633,98],{"class":80},[44,635,46],{"class":84},[44,637,81],{"class":80},[44,639,85],{"class":84},[44,641,642],{"class":80},"()))\n",[20,644,107],{},[35,646,648],{"className":37,"code":647,"language":39,"meta":40,"style":40},"'Python basics\\n'\n'Python basics'\n",[15,649,650,665],{"__ignoreMap":40},[44,651,652,656,659,662],{"class":46,"line":47},[44,653,655],{"class":654},"s2W-s","'",[44,657,602],{"class":658},"sithA",[44,660,606],{"class":661},"sfi6f",[44,663,664],{"class":654},"'\n",[44,666,667,669,671],{"class":46,"line":69},[44,668,655],{"class":654},[44,670,602],{"class":658},[44,672,664],{"class":654},[20,674,675,676,679,680,81],{},"Using ",[15,677,678],{},"repr()"," helps you see hidden characters like ",[15,681,606],{},[20,683,684,685,81],{},"If you are working with files, see ",[243,686,688],{"href":687},"\u002Fhow-to\u002Fhow-to-read-a-file-line-by-line-in-python\u002F","how to read a file line by line in Python",[30,690,692],{"id":691},"remove-specific-characters","Remove specific characters",[20,694,695,696,81],{},"You can pass characters as an argument, such as ",[15,697,698],{},"strip(\"!?\")",[20,700,701],{},"Python will:",[139,703,704,707,710],{},[142,705,706],{},"Remove any matching character from both ends",[142,708,709],{},"Keep removing until it finds a character that is not in the set",[142,711,712],{},"Leave the middle of the string unchanged",[20,714,161],{},[35,716,718],{"className":37,"code":717,"language":39,"meta":40,"style":40},"text = \"??hello!!\"\nprint(text.strip(\"!?\"))\n",[15,719,720,733],{"__ignoreMap":40},[44,721,722,724,726,728,731],{"class":46,"line":47},[44,723,51],{"class":50},[44,725,55],{"class":54},[44,727,59],{"class":58},[44,729,730],{"class":62},"??hello!!",[44,732,66],{"class":58},[44,734,735,737,739,741,743,745,747,749,751,753],{"class":46,"line":69},[44,736,95],{"class":94},[44,738,98],{"class":80},[44,740,194],{"class":84},[44,742,81],{"class":80},[44,744,85],{"class":84},[44,746,98],{"class":80},[44,748,362],{"class":58},[44,750,365],{"class":62},[44,752,362],{"class":58},[44,754,370],{"class":80},[20,756,107],{},[35,758,759],{"className":37,"code":110,"language":39,"meta":40,"style":40},[15,760,761],{"__ignoreMap":40},[44,762,763],{"class":46,"line":47},[44,764,110],{"class":50},[20,766,767],{},"Another example:",[35,769,771],{"className":37,"code":770,"language":39,"meta":40,"style":40},"text = \"abcHelloCba\"\nprint(text.strip(\"abc\"))\n",[15,772,773,786],{"__ignoreMap":40},[44,774,775,777,779,781,784],{"class":46,"line":47},[44,776,51],{"class":50},[44,778,55],{"class":54},[44,780,59],{"class":58},[44,782,783],{"class":62},"abcHelloCba",[44,785,66],{"class":58},[44,787,788,790,792,794,796,798,800,802,805,807],{"class":46,"line":69},[44,789,95],{"class":94},[44,791,98],{"class":80},[44,793,194],{"class":84},[44,795,81],{"class":80},[44,797,85],{"class":84},[44,799,98],{"class":80},[44,801,362],{"class":58},[44,803,804],{"class":62},"abc",[44,806,362],{"class":58},[44,808,370],{"class":80},[20,810,107],{},[35,812,814],{"className":37,"code":813,"language":39,"meta":40,"style":40},"HelloC\n",[15,815,816],{"__ignoreMap":40},[44,817,818],{"class":46,"line":47},[44,819,813],{"class":50},[20,821,822],{},"This can surprise beginners.",[20,824,825,828,829,833,834,836,837,839,840,843,844,847],{},[15,826,827],{},"strip(\"abc\")"," does ",[830,831,832],"strong",{},"not"," mean “remove the exact text ",[15,835,804],{}," once”. It means “remove any ",[15,838,243],{},", ",[15,841,842],{},"b",", or ",[15,845,846],{},"c"," characters from both ends”.",[20,849,850],{},"It also does not remove characters from the middle.",[20,852,853,854,860],{},"If you need to replace text anywhere in a string, use ",[243,855,857],{"href":856},"\u002Freference\u002Fpython-string-replace-method\u002F",[15,858,859],{},"replace()"," instead.",[30,862,864,866,867,866,870],{"id":863},"strip-vs-lstrip-vs-rstrip",[15,865,17],{}," vs ",[15,868,869],{},"lstrip()",[15,871,872],{},"rstrip()",[20,874,875],{},"These methods are similar, but they remove characters from different sides.",[139,877,878,883,888],{},[142,879,880,882],{},[15,881,17],{}," removes from both ends",[142,884,885,887],{},[15,886,869],{}," removes from the left side only",[142,889,890,892],{},[15,891,872],{}," removes from the right side only",[20,894,161],{},[35,896,898],{"className":37,"code":897,"language":39,"meta":40,"style":40},"text = \"  hello  \"\n\nprint(repr(text.strip()))\nprint(repr(text.lstrip()))\nprint(repr(text.rstrip()))\n",[15,899,900,912,916,934,953],{"__ignoreMap":40},[44,901,902,904,906,908,910],{"class":46,"line":47},[44,903,51],{"class":50},[44,905,55],{"class":54},[44,907,59],{"class":58},[44,909,63],{"class":62},[44,911,66],{"class":58},[44,913,914],{"class":46,"line":69},[44,915,185],{"emptyLinePlaceholder":184},[44,917,918,920,922,924,926,928,930,932],{"class":46,"line":91},[44,919,95],{"class":94},[44,921,98],{"class":80},[44,923,617],{"class":94},[44,925,98],{"class":80},[44,927,194],{"class":84},[44,929,81],{"class":80},[44,931,85],{"class":84},[44,933,642],{"class":80},[44,935,936,938,940,942,944,946,948,951],{"class":46,"line":204},[44,937,95],{"class":94},[44,939,98],{"class":80},[44,941,617],{"class":94},[44,943,98],{"class":80},[44,945,194],{"class":84},[44,947,81],{"class":80},[44,949,950],{"class":84},"lstrip",[44,952,642],{"class":80},[44,954,956,958,960,962,964,966,968,971],{"class":46,"line":955},5,[44,957,95],{"class":94},[44,959,98],{"class":80},[44,961,617],{"class":94},[44,963,98],{"class":80},[44,965,194],{"class":84},[44,967,81],{"class":80},[44,969,970],{"class":84},"rstrip",[44,972,642],{"class":80},[20,974,107],{},[35,976,978],{"className":37,"code":977,"language":39,"meta":40,"style":40},"'hello'\n'hello  '\n'  hello'\n",[15,979,980,989,998],{"__ignoreMap":40},[44,981,982,984,987],{"class":46,"line":47},[44,983,655],{"class":654},[44,985,986],{"class":658},"hello",[44,988,664],{"class":654},[44,990,991,993,996],{"class":46,"line":69},[44,992,655],{"class":654},[44,994,995],{"class":658},"hello  ",[44,997,664],{"class":654},[44,999,1000,1002,1005],{"class":46,"line":91},[44,1001,655],{"class":654},[44,1003,1004],{"class":658},"  hello",[44,1006,664],{"class":654},[20,1008,1009],{},"Choose the method based on which side needs cleaning.",[30,1011,1013],{"id":1012},"important-behavior-to-understand","Important behavior to understand",[20,1015,1016],{},"These points are worth remembering:",[139,1018,1019,1028,1038,1041],{},[142,1020,1021,1023,1024,1027],{},[15,1022,827],{}," does not remove the exact text ",[15,1025,1026],{},"\"abc\""," once",[142,1029,1030,1031,839,1033,843,1035,1037],{},"It removes any of the characters ",[15,1032,243],{},[15,1034,842],{},[15,1036,846],{}," from both ends",[142,1039,1040],{},"Middle characters are untouched",[142,1042,1043],{},"Save the result to a variable if you want to use the cleaned string",[20,1045,161],{},[35,1047,1049],{"className":37,"code":1048,"language":39,"meta":40,"style":40},"filename = \"txt_report.txt\"\nprint(filename.strip(\".txt\"))\n",[15,1050,1051,1065],{"__ignoreMap":40},[44,1052,1053,1056,1058,1060,1063],{"class":46,"line":47},[44,1054,1055],{"class":50},"filename ",[44,1057,55],{"class":54},[44,1059,59],{"class":58},[44,1061,1062],{"class":62},"txt_report.txt",[44,1064,66],{"class":58},[44,1066,1067,1069,1071,1074,1076,1078,1080,1082,1085,1087],{"class":46,"line":69},[44,1068,95],{"class":94},[44,1070,98],{"class":80},[44,1072,1073],{"class":84},"filename",[44,1075,81],{"class":80},[44,1077,85],{"class":84},[44,1079,98],{"class":80},[44,1081,362],{"class":58},[44,1083,1084],{"class":62},".txt",[44,1086,362],{"class":58},[44,1088,370],{"class":80},[20,1090,107],{},[35,1092,1094],{"className":37,"code":1093,"language":39,"meta":40,"style":40},"_report\n",[15,1095,1096],{"__ignoreMap":40},[44,1097,1098],{"class":46,"line":47},[44,1099,1093],{"class":50},[20,1101,1102,1103,839,1105,843,1108,1111],{},"This happens because Python removes any ",[15,1104,81],{},[15,1106,1107],{},"t",[15,1109,1110],{},"x"," characters from both ends.",[20,1113,1114,1115,1118,1119,1121],{},"So ",[15,1116,1117],{},"strip(\".txt\")"," is ",[830,1120,832],{}," a safe way to remove a file extension.",[20,1123,1124,1125,1129],{},"If you need to change exact text in a string, ",[243,1126,1127],{"href":856},[15,1128,859],{}," is often a better fit for simple cases.",[30,1131,1133,1134],{"id":1132},"when-to-use-strip","When to use ",[15,1135,17],{},[20,1137,119,1138,1140],{},[15,1139,17],{}," when you need to clean text at the edges of a string.",[20,1142,1143],{},"Common cases:",[139,1145,1146,1150,1152,1155],{},[142,1147,416,1148,420],{},[15,1149,419],{},[142,1151,423],{},[142,1153,1154],{},"Removing accidental spaces before validation",[142,1156,1157],{},"Preparing text before comparisons",[20,1159,161],{},[35,1161,1163],{"className":37,"code":1162,"language":39,"meta":40,"style":40},"email = \"  user@example.com  \"\n\nif email.strip():\n    print(\"Email was entered\")\n",[15,1164,1165,1179,1183,1197],{"__ignoreMap":40},[44,1166,1167,1170,1172,1174,1177],{"class":46,"line":47},[44,1168,1169],{"class":50},"email ",[44,1171,55],{"class":54},[44,1173,59],{"class":58},[44,1175,1176],{"class":62},"  user@example.com  ",[44,1178,66],{"class":58},[44,1180,1181],{"class":46,"line":69},[44,1182,185],{"emptyLinePlaceholder":184},[44,1184,1185,1187,1190,1192,1194],{"class":46,"line":91},[44,1186,525],{"class":524},[44,1188,1189],{"class":50}," email",[44,1191,81],{"class":80},[44,1193,85],{"class":84},[44,1195,1196],{"class":80},"():\n",[44,1198,1199,1201,1203,1205,1208,1210],{"class":46,"line":204},[44,1200,553],{"class":94},[44,1202,98],{"class":80},[44,1204,362],{"class":58},[44,1206,1207],{"class":62},"Email was entered",[44,1209,362],{"class":58},[44,1211,104],{"class":80},[20,1213,107],{},[35,1215,1217],{"className":37,"code":1216,"language":39,"meta":40,"style":40},"Email was entered\n",[15,1218,1219],{"__ignoreMap":40},[44,1220,1221],{"class":46,"line":47},[44,1222,1216],{"class":50},[20,1224,1225,1226,1228,1229,81],{},"You may also combine ",[15,1227,17],{}," with other string methods. For example, after removing extra spaces, you might convert text to lowercase with ",[243,1230,1232],{"href":1231},"\u002Freference\u002Fpython-string-lower-method\u002F",[15,1233,1234],{},"lower()",[30,1236,1238],{"id":1237},"common-mistakes","Common mistakes",[20,1240,1241],{},"Beginners often run into these problems:",[139,1243,1244,1250,1255,1260],{},[142,1245,1246,1247,1249],{},"Expecting ",[15,1248,17],{}," to change the original string",[142,1251,1246,1252,1254],{},[15,1253,17],{}," to remove text from the middle",[142,1256,675,1257,1259],{},[15,1258,1117],{}," and expecting only the exact file extension to be removed",[142,1261,1262,1263,1266],{},"Forgetting that ",[15,1264,1265],{},"strip(chars)"," removes any matching characters, not a whole substring",[20,1268,1269],{},"Here is a quick debugging example:",[35,1271,1273],{"className":37,"code":1272,"language":39,"meta":40,"style":40},"text = \"  hello\\n\"\n\nprint(text)\nprint(repr(text))\nprint(text.strip())\nprint(repr(text.strip()))\n",[15,1274,1275,1289,1293,1303,1317,1331],{"__ignoreMap":40},[44,1276,1277,1279,1281,1283,1285,1287],{"class":46,"line":47},[44,1278,51],{"class":50},[44,1280,55],{"class":54},[44,1282,59],{"class":58},[44,1284,1004],{"class":62},[44,1286,606],{"class":605},[44,1288,66],{"class":58},[44,1290,1291],{"class":46,"line":69},[44,1292,185],{"emptyLinePlaceholder":184},[44,1294,1295,1297,1299,1301],{"class":46,"line":91},[44,1296,95],{"class":94},[44,1298,98],{"class":80},[44,1300,194],{"class":84},[44,1302,104],{"class":80},[44,1304,1305,1307,1309,1311,1313,1315],{"class":46,"line":204},[44,1306,95],{"class":94},[44,1308,98],{"class":80},[44,1310,617],{"class":94},[44,1312,98],{"class":80},[44,1314,194],{"class":84},[44,1316,370],{"class":80},[44,1318,1319,1321,1323,1325,1327,1329],{"class":46,"line":955},[44,1320,95],{"class":94},[44,1322,98],{"class":80},[44,1324,194],{"class":84},[44,1326,81],{"class":80},[44,1328,85],{"class":84},[44,1330,201],{"class":80},[44,1332,1334,1336,1338,1340,1342,1344,1346,1348],{"class":46,"line":1333},6,[44,1335,95],{"class":94},[44,1337,98],{"class":80},[44,1339,617],{"class":94},[44,1341,98],{"class":80},[44,1343,194],{"class":84},[44,1345,81],{"class":80},[44,1347,85],{"class":84},[44,1349,642],{"class":80},[20,1351,107],{},[35,1353,1355],{"className":37,"code":1354,"language":39,"meta":40,"style":40},"  hello\n\n'  hello\\n'\nhello\n'hello'\n",[15,1356,1357,1362,1366,1376,1380],{"__ignoreMap":40},[44,1358,1359],{"class":46,"line":47},[44,1360,1361],{"class":50},"  hello\n",[44,1363,1364],{"class":46,"line":69},[44,1365,185],{"emptyLinePlaceholder":184},[44,1367,1368,1370,1372,1374],{"class":46,"line":91},[44,1369,655],{"class":654},[44,1371,1004],{"class":658},[44,1373,606],{"class":661},[44,1375,664],{"class":654},[44,1377,1378],{"class":46,"line":204},[44,1379,110],{"class":50},[44,1381,1382,1384,1386],{"class":46,"line":955},[44,1383,655],{"class":654},[44,1385,986],{"class":658},[44,1387,664],{"class":654},[20,1389,1390],{},"Useful debugging commands:",[35,1392,1394],{"className":37,"code":1393,"language":39,"meta":40,"style":40},"print(text)\nprint(repr(text))\nprint(text.strip())\nprint(repr(text.strip()))\nhelp(str.strip)\n",[15,1395,1396,1406,1420,1434,1452],{"__ignoreMap":40},[44,1397,1398,1400,1402,1404],{"class":46,"line":47},[44,1399,95],{"class":94},[44,1401,98],{"class":80},[44,1403,194],{"class":84},[44,1405,104],{"class":80},[44,1407,1408,1410,1412,1414,1416,1418],{"class":46,"line":69},[44,1409,95],{"class":94},[44,1411,98],{"class":80},[44,1413,617],{"class":94},[44,1415,98],{"class":80},[44,1417,194],{"class":84},[44,1419,370],{"class":80},[44,1421,1422,1424,1426,1428,1430,1432],{"class":46,"line":91},[44,1423,95],{"class":94},[44,1425,98],{"class":80},[44,1427,194],{"class":84},[44,1429,81],{"class":80},[44,1431,85],{"class":84},[44,1433,201],{"class":80},[44,1435,1436,1438,1440,1442,1444,1446,1448,1450],{"class":46,"line":204},[44,1437,95],{"class":94},[44,1439,98],{"class":80},[44,1441,617],{"class":94},[44,1443,98],{"class":80},[44,1445,194],{"class":84},[44,1447,81],{"class":80},[44,1449,85],{"class":84},[44,1451,642],{"class":80},[44,1453,1454,1457,1459,1463,1465,1468],{"class":46,"line":955},[44,1455,1456],{"class":94},"help",[44,1458,98],{"class":80},[44,1460,1462],{"class":1461},"sZMiF","str",[44,1464,81],{"class":80},[44,1466,85],{"class":1467},"skxfh",[44,1469,104],{"class":80},[20,1471,1472,1474],{},[15,1473,678],{}," is very helpful because it shows hidden whitespace clearly.",[30,1476,1478],{"id":1477},"faq","FAQ",[267,1480,1482,1483,1485],{"id":1481},"does-strip-remove-spaces-in-the-middle-of-a-string","Does ",[15,1484,17],{}," remove spaces in the middle of a string?",[20,1487,1488,1489,1491],{},"No. ",[15,1490,17],{}," only removes characters from the start and end of the string.",[267,1493,1482,1495,1497],{"id":1494},"does-strip-change-the-original-string",[15,1496,17],{}," change the original string?",[20,1499,1500],{},"No. It returns a new string because Python strings are immutable.",[267,1502,1504,1505,1507],{"id":1503},"what-does-strip-remove-by-default","What does ",[15,1506,17],{}," remove by default?",[20,1509,1510],{},"It removes whitespace such as spaces, tabs, and newline characters from both ends.",[267,1512,1514,1515,1517,1518,1520],{"id":1513},"how-is-strip-different-from-replace","How is ",[15,1516,17],{}," different from ",[15,1519,859],{},"?",[20,1522,1523,1525,1526,1528],{},[15,1524,17],{}," removes characters only from the ends. ",[15,1527,859],{}," can change matching text anywhere in the string.",[267,1530,1532],{"id":1531},"can-i-remove-only-the-left-or-right-side","Can I remove only the left or right side?",[20,1534,1535,1536,1538,1539,1541],{},"Yes. Use ",[15,1537,869],{}," for the left side and ",[15,1540,872],{}," for the right side.",[30,1543,1545],{"id":1544},"see-also","See also",[139,1547,1548,1556,1562,1567,1572],{},[142,1549,1550],{},[243,1551,1552,1553,1555],{"href":1231},"Python string ",[15,1554,1234],{}," method",[142,1557,1558],{},[243,1559,1552,1560,1555],{"href":856},[15,1561,859],{},[142,1563,1564],{},[243,1565,1566],{"href":581},"How to remove whitespace from a string in Python",[142,1568,1569],{},[243,1570,1571],{"href":687},"How to read a file line by line in Python",[142,1573,1574],{},[243,1575,246],{"href":245},[1577,1578,1579],"style",{},"html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .s2W-s, html code.shiki .s2W-s{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#032F62;--shiki-default-font-style:inherit;--shiki-dark:#9ECBFF;--shiki-dark-font-style:inherit}html pre.shiki code .sithA, html code.shiki .sithA{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#032F62;--shiki-default-font-style:inherit;--shiki-dark:#9ECBFF;--shiki-dark-font-style:inherit}html pre.shiki code .sfi6f, html code.shiki .sfi6f{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#005CC5;--shiki-default-font-style:inherit;--shiki-dark:#79B8FF;--shiki-dark-font-style:inherit}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}",{"title":40,"searchDepth":69,"depth":69,"links":1581},[1582,1583,1585,1589,1591,1592,1594,1595,1597,1598,1609],{"id":32,"depth":69,"text":33},{"id":125,"depth":69,"text":1584},"What strip() does",{"id":249,"depth":69,"text":250,"children":1586},[1587,1588],{"id":269,"depth":91,"text":260},{"id":322,"depth":91,"text":265},{"id":400,"depth":69,"text":1590},"Remove whitespace with strip()",{"id":691,"depth":69,"text":692},{"id":863,"depth":69,"text":1593},"strip() vs lstrip() vs rstrip()",{"id":1012,"depth":69,"text":1013},{"id":1132,"depth":69,"text":1596},"When to use strip()",{"id":1237,"depth":69,"text":1238},{"id":1477,"depth":69,"text":1478,"children":1599},[1600,1602,1604,1606,1608],{"id":1481,"depth":91,"text":1601},"Does strip() remove spaces in the middle of a string?",{"id":1494,"depth":91,"text":1603},"Does strip() change the original string?",{"id":1503,"depth":91,"text":1605},"What does strip() remove by default?",{"id":1513,"depth":91,"text":1607},"How is strip() different from replace()?",{"id":1531,"depth":91,"text":1532},{"id":1544,"depth":69,"text":1545},"Master python string strip method in our comprehensive Python beginner guide.","md",{},"\u002Freference\u002Fpython-string-strip-method",{"title":5,"description":1610},"reference\u002Fpython-string-strip-method","V33HNckrK0iU0Rb4v9xwAECg55fn4E8r6Jrd6VFtyd0",1777585506295]