[{"data":1,"prerenderedAt":1496},["ShallowReactive",2],{"doc-\u002Fglossary\u002Fwhat-is-a-string-in-python":3},{"id":4,"title":5,"body":6,"description":1489,"extension":1490,"meta":1491,"navigation":98,"path":1492,"seo":1493,"stem":1494,"__hash__":1495},"content\u002Fglossary\u002Fwhat-is-a-string-in-python.md","What Is a String in Python?",{"type":7,"value":8,"toc":1462},"minimark",[9,13,17,20,40,43,130,133,148,151,156,159,162,187,190,203,206,268,272,275,278,292,333,335,374,386,390,393,416,419,497,500,504,507,515,572,574,583,590,616,618,627,631,634,694,696,711,715,771,773,789,793,875,877,927,948,952,955,958,960,1002,1004,1019,1022,1040,1043,1105,1107,1115,1130,1134,1142,1145,1156,1159,1163,1166,1185,1188,1229,1235,1238,1280,1283,1328,1331,1342,1346,1350,1355,1364,1372,1376,1385,1389,1392,1399,1402,1406,1458],[10,11,5],"h1",{"id":12},"what-is-a-string-in-python",[14,15,16],"p",{},"A string in Python is a value used to store text.",[14,18,19],{},"Beginners use strings all the time. A string can hold:",[21,22,23,27,30,33],"ul",{},[24,25,26],"li",{},"A word",[24,28,29],{},"A sentence",[24,31,32],{},"A number written as text",[24,34,35,36],{},"Even empty text like ",[37,38,39],"code",{},"\"\"",[14,41,42],{},"Python knows something is a string when it is written inside quotes. This page defines the term clearly and shows where strings are commonly used.",[44,45,50],"pre",{"className":46,"code":47,"language":48,"meta":49,"style":49},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","name = \"Alice\"\nmessage = 'Hello'\n\nprint(name)\nprint(message)\n","python","",[37,51,52,76,93,100,118],{"__ignoreMap":49},[53,54,57,61,65,69,73],"span",{"class":55,"line":56},"line",1,[53,58,60],{"class":59},"su5hD","name ",[53,62,64],{"class":63},"smGrS","=",[53,66,68],{"class":67},"sjJ54"," \"",[53,70,72],{"class":71},"s_sjI","Alice",[53,74,75],{"class":67},"\"\n",[53,77,79,82,84,87,90],{"class":55,"line":78},2,[53,80,81],{"class":59},"message ",[53,83,64],{"class":63},[53,85,86],{"class":67}," '",[53,88,89],{"class":71},"Hello",[53,91,92],{"class":67},"'\n",[53,94,96],{"class":55,"line":95},3,[53,97,99],{"emptyLinePlaceholder":98},true,"\n",[53,101,103,107,111,115],{"class":55,"line":102},4,[53,104,106],{"class":105},"sptTA","print",[53,108,110],{"class":109},"sP7_E","(",[53,112,114],{"class":113},"slqww","name",[53,116,117],{"class":109},")\n",[53,119,121,123,125,128],{"class":55,"line":120},5,[53,122,106],{"class":105},[53,124,110],{"class":109},[53,126,127],{"class":113},"message",[53,129,117],{"class":109},[14,131,132],{},"Output:",[44,134,136],{"className":46,"code":135,"language":48,"meta":49,"style":49},"Alice\nHello\n",[37,137,138,143],{"__ignoreMap":49},[53,139,140],{"class":55,"line":56},[53,141,142],{"class":59},"Alice\n",[53,144,145],{"class":55,"line":78},[53,146,147],{"class":59},"Hello\n",[14,149,150],{},"A string is text inside quotes. Python treats quoted text as a string value.",[152,153,155],"h2",{"id":154},"what-a-string-is","What a string is",[14,157,158],{},"A string is a value used to store text.",[14,160,161],{},"Strings can contain:",[21,163,164,170,176,182],{},[24,165,166,167],{},"Words like ",[37,168,169],{},"\"hello\"",[24,171,172,173],{},"Names like ",[37,174,175],{},"'Python'",[24,177,178,179],{},"Digits written as text like ",[37,180,181],{},"\"123\"",[24,183,184,185],{},"Empty text like ",[37,186,39],{},[14,188,189],{},"In Python, strings are written inside:",[21,191,192,198],{},[24,193,194,195],{},"Single quotes: ",[37,196,197],{},"'hello'",[24,199,200,201],{},"Double quotes: ",[37,202,169],{},[14,204,205],{},"These are all strings:",[44,207,209],{"className":46,"code":208,"language":48,"meta":49,"style":49},"print(\"hello\")\nprint('Python')\nprint(\"123\")\nprint(\"\")\n",[37,210,211,227,243,258],{"__ignoreMap":49},[53,212,213,215,217,220,223,225],{"class":55,"line":56},[53,214,106],{"class":105},[53,216,110],{"class":109},[53,218,219],{"class":67},"\"",[53,221,222],{"class":71},"hello",[53,224,219],{"class":67},[53,226,117],{"class":109},[53,228,229,231,233,236,239,241],{"class":55,"line":78},[53,230,106],{"class":105},[53,232,110],{"class":109},[53,234,235],{"class":67},"'",[53,237,238],{"class":71},"Python",[53,240,235],{"class":67},[53,242,117],{"class":109},[53,244,245,247,249,251,254,256],{"class":55,"line":95},[53,246,106],{"class":105},[53,248,110],{"class":109},[53,250,219],{"class":67},[53,252,253],{"class":71},"123",[53,255,219],{"class":67},[53,257,117],{"class":109},[53,259,260,262,264,266],{"class":55,"line":102},[53,261,106],{"class":105},[53,263,110],{"class":109},[53,265,39],{"class":67},[53,267,117],{"class":109},[152,269,271],{"id":270},"how-python-knows-something-is-a-string","How Python knows something is a string",[14,273,274],{},"Python checks for quotes around the value.",[14,276,277],{},"For example:",[21,279,280,286],{},[24,281,282,285],{},[37,283,284],{},"\"42\""," is a string because it has quotes",[24,287,288,291],{},[37,289,290],{},"42"," is an integer because it has no quotes",[44,293,295],{"className":46,"code":294,"language":48,"meta":49,"style":49},"print(type(\"42\"))\nprint(type(42))\n",[37,296,297,318],{"__ignoreMap":49},[53,298,299,301,303,307,309,311,313,315],{"class":55,"line":56},[53,300,106],{"class":105},[53,302,110],{"class":109},[53,304,306],{"class":305},"sZMiF","type",[53,308,110],{"class":109},[53,310,219],{"class":67},[53,312,290],{"class":71},[53,314,219],{"class":67},[53,316,317],{"class":109},"))\n",[53,319,320,322,324,326,328,331],{"class":55,"line":78},[53,321,106],{"class":105},[53,323,110],{"class":109},[53,325,306],{"class":305},[53,327,110],{"class":109},[53,329,290],{"class":330},"srdBf",[53,332,317],{"class":109},[14,334,132],{},[44,336,338],{"className":46,"code":337,"language":48,"meta":49,"style":49},"\u003Cclass 'str'>\n\u003Cclass 'int'>\n",[37,339,340,359],{"__ignoreMap":49},[53,341,342,345,349,351,354,356],{"class":55,"line":56},[53,343,344],{"class":63},"\u003C",[53,346,348],{"class":347},"sbsja","class",[53,350,86],{"class":67},[53,352,353],{"class":71},"str",[53,355,235],{"class":67},[53,357,358],{"class":63},">\n",[53,360,361,363,365,367,370,372],{"class":55,"line":78},[53,362,344],{"class":63},[53,364,348],{"class":347},[53,366,86],{"class":67},[53,368,369],{"class":71},"int",[53,371,235],{"class":67},[53,373,358],{"class":63},[14,375,376,377,385],{},"Even when they look similar, strings and numbers are different types of values. If you want to inspect a value, the ",[378,379,381,384],"a",{"href":380},"\u002Freference\u002Fpython-type-function-explained\u002F",[37,382,383],{},"type()"," function"," is very useful.",[152,387,389],{"id":388},"common-places-beginners-use-strings","Common places beginners use strings",[14,391,392],{},"Beginners often use strings for:",[21,394,395,398,404,410,413],{},[24,396,397],{},"Names",[24,399,400,401],{},"Messages shown with ",[37,402,403],{},"print()",[24,405,406,407],{},"User input from ",[37,408,409],{},"input()",[24,411,412],{},"File names and file paths",[24,414,415],{},"Data read from files or APIs",[14,417,418],{},"Example:",[44,420,422],{"className":46,"code":421,"language":48,"meta":49,"style":49},"name = \"Maya\"\nfilename = \"notes.txt\"\n\nprint(\"Hello, \" + name)\nprint(\"Opening file:\", filename)\n",[37,423,424,437,451,455,476],{"__ignoreMap":49},[53,425,426,428,430,432,435],{"class":55,"line":56},[53,427,60],{"class":59},[53,429,64],{"class":63},[53,431,68],{"class":67},[53,433,434],{"class":71},"Maya",[53,436,75],{"class":67},[53,438,439,442,444,446,449],{"class":55,"line":78},[53,440,441],{"class":59},"filename ",[53,443,64],{"class":63},[53,445,68],{"class":67},[53,447,448],{"class":71},"notes.txt",[53,450,75],{"class":67},[53,452,453],{"class":55,"line":95},[53,454,99],{"emptyLinePlaceholder":98},[53,456,457,459,461,463,466,468,471,474],{"class":55,"line":102},[53,458,106],{"class":105},[53,460,110],{"class":109},[53,462,219],{"class":67},[53,464,465],{"class":71},"Hello, ",[53,467,219],{"class":67},[53,469,470],{"class":63}," +",[53,472,473],{"class":113}," name",[53,475,117],{"class":109},[53,477,478,480,482,484,487,489,492,495],{"class":55,"line":120},[53,479,106],{"class":105},[53,481,110],{"class":109},[53,483,219],{"class":67},[53,485,486],{"class":71},"Opening file:",[53,488,219],{"class":67},[53,490,491],{"class":109},",",[53,493,494],{"class":113}," filename",[53,496,117],{"class":109},[14,498,499],{},"In many beginner programs, most visible text is stored as strings.",[152,501,503],{"id":502},"what-you-can-do-with-strings","What you can do with strings",[14,505,506],{},"Strings are not just for storing text. You can also work with them in useful ways.",[508,509,511,512],"h3",{"id":510},"join-text-together-with","Join text together with ",[37,513,514],{},"+",[44,516,518],{"className":46,"code":517,"language":48,"meta":49,"style":49},"first = \"Hello\"\nsecond = \"World\"\n\nprint(first + \" \" + second)\n",[37,519,520,533,547,551],{"__ignoreMap":49},[53,521,522,525,527,529,531],{"class":55,"line":56},[53,523,524],{"class":59},"first ",[53,526,64],{"class":63},[53,528,68],{"class":67},[53,530,89],{"class":71},[53,532,75],{"class":67},[53,534,535,538,540,542,545],{"class":55,"line":78},[53,536,537],{"class":59},"second ",[53,539,64],{"class":63},[53,541,68],{"class":67},[53,543,544],{"class":71},"World",[53,546,75],{"class":67},[53,548,549],{"class":55,"line":95},[53,550,99],{"emptyLinePlaceholder":98},[53,552,553,555,557,559,561,563,565,567,570],{"class":55,"line":102},[53,554,106],{"class":105},[53,556,110],{"class":109},[53,558,524],{"class":113},[53,560,514],{"class":63},[53,562,68],{"class":67},[53,564,68],{"class":67},[53,566,470],{"class":63},[53,568,569],{"class":113}," second",[53,571,117],{"class":109},[14,573,132],{},[44,575,577],{"className":46,"code":576,"language":48,"meta":49,"style":49},"Hello World\n",[37,578,579],{"__ignoreMap":49},[53,580,581],{"class":55,"line":56},[53,582,576],{"class":59},[508,584,586,587],{"id":585},"repeat-text-with","Repeat text with ",[37,588,589],{},"*",[44,591,593],{"className":46,"code":592,"language":48,"meta":49,"style":49},"print(\"ha\" * 3)\n",[37,594,595],{"__ignoreMap":49},[53,596,597,599,601,603,606,608,611,614],{"class":55,"line":56},[53,598,106],{"class":105},[53,600,110],{"class":109},[53,602,219],{"class":67},[53,604,605],{"class":71},"ha",[53,607,219],{"class":67},[53,609,610],{"class":63}," *",[53,612,613],{"class":330}," 3",[53,615,117],{"class":109},[14,617,132],{},[44,619,621],{"className":46,"code":620,"language":48,"meta":49,"style":49},"hahaha\n",[37,622,623],{"__ignoreMap":49},[53,624,625],{"class":55,"line":56},[53,626,620],{"class":59},[508,628,630],{"id":629},"get-part-of-a-string","Get part of a string",[14,632,633],{},"You can access characters by position or take a slice of the string.",[44,635,637],{"className":46,"code":636,"language":48,"meta":49,"style":49},"word = \"Python\"\n\nprint(word[0])\nprint(word[0:3])\n",[37,638,639,652,656,674],{"__ignoreMap":49},[53,640,641,644,646,648,650],{"class":55,"line":56},[53,642,643],{"class":59},"word ",[53,645,64],{"class":63},[53,647,68],{"class":67},[53,649,238],{"class":71},[53,651,75],{"class":67},[53,653,654],{"class":55,"line":78},[53,655,99],{"emptyLinePlaceholder":98},[53,657,658,660,662,665,668,671],{"class":55,"line":95},[53,659,106],{"class":105},[53,661,110],{"class":109},[53,663,664],{"class":113},"word",[53,666,667],{"class":109},"[",[53,669,670],{"class":330},"0",[53,672,673],{"class":109},"])\n",[53,675,676,678,680,682,684,686,689,692],{"class":55,"line":102},[53,677,106],{"class":105},[53,679,110],{"class":109},[53,681,664],{"class":113},[53,683,667],{"class":109},[53,685,670],{"class":330},[53,687,688],{"class":109},":",[53,690,691],{"class":330},"3",[53,693,673],{"class":109},[14,695,132],{},[44,697,699],{"className":46,"code":698,"language":48,"meta":49,"style":49},"P\nPyt\n",[37,700,701,706],{"__ignoreMap":49},[53,702,703],{"class":55,"line":56},[53,704,705],{"class":59},"P\n",[53,707,708],{"class":55,"line":78},[53,709,710],{"class":59},"Pyt\n",[508,712,714],{"id":713},"change-letter-case","Change letter case",[44,716,718],{"className":46,"code":717,"language":48,"meta":49,"style":49},"text = \"PyThOn\"\n\nprint(text.lower())\nprint(text.upper())\n",[37,719,720,734,738,756],{"__ignoreMap":49},[53,721,722,725,727,729,732],{"class":55,"line":56},[53,723,724],{"class":59},"text ",[53,726,64],{"class":63},[53,728,68],{"class":67},[53,730,731],{"class":71},"PyThOn",[53,733,75],{"class":67},[53,735,736],{"class":55,"line":78},[53,737,99],{"emptyLinePlaceholder":98},[53,739,740,742,744,747,750,753],{"class":55,"line":95},[53,741,106],{"class":105},[53,743,110],{"class":109},[53,745,746],{"class":113},"text",[53,748,749],{"class":109},".",[53,751,752],{"class":113},"lower",[53,754,755],{"class":109},"())\n",[53,757,758,760,762,764,766,769],{"class":55,"line":102},[53,759,106],{"class":105},[53,761,110],{"class":109},[53,763,746],{"class":113},[53,765,749],{"class":109},[53,767,768],{"class":113},"upper",[53,770,755],{"class":109},[14,772,132],{},[44,774,776],{"className":46,"code":775,"language":48,"meta":49,"style":49},"python\nPYTHON\n",[37,777,778,783],{"__ignoreMap":49},[53,779,780],{"class":55,"line":56},[53,781,782],{"class":59},"python\n",[53,784,785],{"class":55,"line":78},[53,786,788],{"class":787},"s_hVV","PYTHON\n",[508,790,792],{"id":791},"split-text-or-join-parts-together","Split text or join parts together",[44,794,796],{"className":46,"code":795,"language":48,"meta":49,"style":49},"text = \"red,green,blue\"\ncolors = text.split(\",\")\n\nprint(colors)\nprint(\"-\".join(colors))\n",[37,797,798,811,836,840,851],{"__ignoreMap":49},[53,799,800,802,804,806,809],{"class":55,"line":56},[53,801,724],{"class":59},[53,803,64],{"class":63},[53,805,68],{"class":67},[53,807,808],{"class":71},"red,green,blue",[53,810,75],{"class":67},[53,812,813,816,818,821,823,826,828,830,832,834],{"class":55,"line":78},[53,814,815],{"class":59},"colors ",[53,817,64],{"class":63},[53,819,820],{"class":59}," text",[53,822,749],{"class":109},[53,824,825],{"class":113},"split",[53,827,110],{"class":109},[53,829,219],{"class":67},[53,831,491],{"class":71},[53,833,219],{"class":67},[53,835,117],{"class":109},[53,837,838],{"class":55,"line":95},[53,839,99],{"emptyLinePlaceholder":98},[53,841,842,844,846,849],{"class":55,"line":102},[53,843,106],{"class":105},[53,845,110],{"class":109},[53,847,848],{"class":113},"colors",[53,850,117],{"class":109},[53,852,853,855,857,859,862,864,866,869,871,873],{"class":55,"line":120},[53,854,106],{"class":105},[53,856,110],{"class":109},[53,858,219],{"class":67},[53,860,861],{"class":71},"-",[53,863,219],{"class":67},[53,865,749],{"class":109},[53,867,868],{"class":113},"join",[53,870,110],{"class":109},[53,872,848],{"class":113},[53,874,317],{"class":109},[14,876,132],{},[44,878,880],{"className":46,"code":879,"language":48,"meta":49,"style":49},"['red', 'green', 'blue']\nred-green-blue\n",[37,881,882,914],{"__ignoreMap":49},[53,883,884,886,888,891,893,895,897,900,902,904,906,909,911],{"class":55,"line":56},[53,885,667],{"class":109},[53,887,235],{"class":67},[53,889,890],{"class":71},"red",[53,892,235],{"class":67},[53,894,491],{"class":109},[53,896,86],{"class":67},[53,898,899],{"class":71},"green",[53,901,235],{"class":67},[53,903,491],{"class":109},[53,905,86],{"class":67},[53,907,908],{"class":71},"blue",[53,910,235],{"class":67},[53,912,913],{"class":109},"]\n",[53,915,916,918,920,922,924],{"class":55,"line":78},[53,917,890],{"class":59},[53,919,861],{"class":63},[53,921,899],{"class":59},[53,923,861],{"class":63},[53,925,926],{"class":59},"blue\n",[14,928,929,930,934,935,941,942,749],{},"If you want to go deeper, see the beginner lesson on ",[378,931,933],{"href":932},"\u002Flearn\u002Fpython-strings-explained-basics-and-examples\u002F","Python strings explained with basics and examples",". You can also learn specific methods like ",[378,936,938],{"href":937},"\u002Freference\u002Fpython-string-split-method\u002F",[37,939,940],{},"split()"," and ",[378,943,945],{"href":944},"\u002Freference\u002Fpython-string-join-method\u002F",[37,946,947],{},"join()",[152,949,951],{"id":950},"important-beginner-idea","Important beginner idea",[14,953,954],{},"Strings are text, not numbers.",[14,956,957],{},"This is one of the most important beginner ideas to understand.",[14,959,277],{},[44,961,963],{"className":46,"code":962,"language":48,"meta":49,"style":49},"print(\"5\" + \"3\")\nprint(5 + 3)\n",[37,964,965,988],{"__ignoreMap":49},[53,966,967,969,971,973,976,978,980,982,984,986],{"class":55,"line":56},[53,968,106],{"class":105},[53,970,110],{"class":109},[53,972,219],{"class":67},[53,974,975],{"class":71},"5",[53,977,219],{"class":67},[53,979,470],{"class":63},[53,981,68],{"class":67},[53,983,691],{"class":71},[53,985,219],{"class":67},[53,987,117],{"class":109},[53,989,990,992,994,996,998,1000],{"class":55,"line":78},[53,991,106],{"class":105},[53,993,110],{"class":109},[53,995,975],{"class":330},[53,997,470],{"class":63},[53,999,613],{"class":330},[53,1001,117],{"class":109},[14,1003,132],{},[44,1005,1007],{"className":46,"code":1006,"language":48,"meta":49,"style":49},"53\n8\n",[37,1008,1009,1014],{"__ignoreMap":49},[53,1010,1011],{"class":55,"line":56},[53,1012,1013],{"class":330},"53\n",[53,1015,1016],{"class":55,"line":78},[53,1017,1018],{"class":330},"8\n",[14,1020,1021],{},"Why?",[21,1023,1024,1033],{},[24,1025,1026,941,1029,1032],{},[37,1027,1028],{},"\"5\"",[37,1030,1031],{},"\"3\""," are strings, so Python joins them",[24,1034,1035,941,1037,1039],{},[37,1036,975],{},[37,1038,691],{}," are numbers, so Python adds them",[14,1041,1042],{},"If you need math, convert the string first:",[44,1044,1046],{"className":46,"code":1045,"language":48,"meta":49,"style":49},"a = \"5\"\nb = \"3\"\n\nprint(int(a) + int(b))\n",[37,1047,1048,1061,1074,1078],{"__ignoreMap":49},[53,1049,1050,1053,1055,1057,1059],{"class":55,"line":56},[53,1051,1052],{"class":59},"a ",[53,1054,64],{"class":63},[53,1056,68],{"class":67},[53,1058,975],{"class":71},[53,1060,75],{"class":67},[53,1062,1063,1066,1068,1070,1072],{"class":55,"line":78},[53,1064,1065],{"class":59},"b ",[53,1067,64],{"class":63},[53,1069,68],{"class":67},[53,1071,691],{"class":71},[53,1073,75],{"class":67},[53,1075,1076],{"class":55,"line":95},[53,1077,99],{"emptyLinePlaceholder":98},[53,1079,1080,1082,1084,1086,1088,1090,1093,1095,1098,1100,1103],{"class":55,"line":102},[53,1081,106],{"class":105},[53,1083,110],{"class":109},[53,1085,369],{"class":305},[53,1087,110],{"class":109},[53,1089,378],{"class":113},[53,1091,1092],{"class":109},")",[53,1094,470],{"class":63},[53,1096,1097],{"class":305}," int",[53,1099,110],{"class":109},[53,1101,1102],{"class":113},"b",[53,1104,317],{"class":109},[14,1106,132],{},[44,1108,1109],{"className":46,"code":1018,"language":48,"meta":49,"style":49},[37,1110,1111],{"__ignoreMap":49},[53,1112,1113],{"class":55,"line":56},[53,1114,1018],{"class":330},[14,1116,1117,1118,1121,1122,1125,1126,749],{},"Use ",[37,1119,1120],{},"int()"," for whole numbers and ",[37,1123,1124],{},"float()"," for decimal numbers. If you need help with this, see ",[378,1127,1129],{"href":1128},"\u002Fhow-to\u002Fhow-to-convert-string-to-int-in-python\u002F","how to convert a string to an integer in Python",[152,1131,1133],{"id":1132},"how-this-page-is-different-from-other-string-pages","How this page is different from other string pages",[14,1135,1136,1137,1141],{},"This page defines the term ",[1138,1139,1140],"strong",{},"string"," only.",[14,1143,1144],{},"It does not fully teach:",[21,1146,1147,1150,1153],{},[24,1148,1149],{},"Every string method",[24,1151,1152],{},"Advanced formatting",[24,1154,1155],{},"All ways to create and modify strings",[14,1157,1158],{},"Use this page to understand the basic meaning of a string. Then move on to deeper pages for creating strings, changing them, splitting them, joining them, and formatting them.",[152,1160,1162],{"id":1161},"common-mistakes","Common mistakes",[14,1164,1165],{},"Beginners often run into these problems with strings:",[21,1167,1168,1171,1174,1179],{},[24,1169,1170],{},"Thinking quoted numbers are real numbers",[24,1172,1173],{},"Forgetting quotes around text",[24,1175,1176,1177],{},"Mixing strings and integers with ",[37,1178,514],{},[24,1180,1181,1182,1184],{},"Expecting ",[37,1183,409],{}," to return a number automatically",[14,1186,1187],{},"Example of a common mistake:",[44,1189,1191],{"className":46,"code":1190,"language":48,"meta":49,"style":49},"age = input(\"Enter your age: \")\nprint(age + 1)\n",[37,1192,1193,1214],{"__ignoreMap":49},[53,1194,1195,1198,1200,1203,1205,1207,1210,1212],{"class":55,"line":56},[53,1196,1197],{"class":59},"age ",[53,1199,64],{"class":63},[53,1201,1202],{"class":105}," input",[53,1204,110],{"class":109},[53,1206,219],{"class":67},[53,1208,1209],{"class":71},"Enter your age: ",[53,1211,219],{"class":67},[53,1213,117],{"class":109},[53,1215,1216,1218,1220,1222,1224,1227],{"class":55,"line":78},[53,1217,106],{"class":105},[53,1219,110],{"class":109},[53,1221,1197],{"class":113},[53,1223,514],{"class":63},[53,1225,1226],{"class":330}," 1",[53,1228,117],{"class":109},[14,1230,1231,1232,1234],{},"This causes an error because ",[37,1233,409],{}," returns a string, and Python cannot add a string and an integer directly.",[14,1236,1237],{},"A correct version is:",[44,1239,1241],{"className":46,"code":1240,"language":48,"meta":49,"style":49},"age = int(input(\"Enter your age: \"))\nprint(age + 1)\n",[37,1242,1243,1266],{"__ignoreMap":49},[53,1244,1245,1247,1249,1251,1253,1256,1258,1260,1262,1264],{"class":55,"line":56},[53,1246,1197],{"class":59},[53,1248,64],{"class":63},[53,1250,1097],{"class":305},[53,1252,110],{"class":109},[53,1254,1255],{"class":105},"input",[53,1257,110],{"class":109},[53,1259,219],{"class":67},[53,1261,1209],{"class":71},[53,1263,219],{"class":67},[53,1265,317],{"class":109},[53,1267,1268,1270,1272,1274,1276,1278],{"class":55,"line":78},[53,1269,106],{"class":105},[53,1271,110],{"class":109},[53,1273,1197],{"class":113},[53,1275,514],{"class":63},[53,1277,1226],{"class":330},[53,1279,117],{"class":109},[14,1281,1282],{},"When debugging string problems, these checks help a lot:",[44,1284,1286],{"className":46,"code":1285,"language":48,"meta":49,"style":49},"print(value)\nprint(type(value))\nprint(len(value))\n",[37,1287,1288,1299,1313],{"__ignoreMap":49},[53,1289,1290,1292,1294,1297],{"class":55,"line":56},[53,1291,106],{"class":105},[53,1293,110],{"class":109},[53,1295,1296],{"class":113},"value",[53,1298,117],{"class":109},[53,1300,1301,1303,1305,1307,1309,1311],{"class":55,"line":78},[53,1302,106],{"class":105},[53,1304,110],{"class":109},[53,1306,306],{"class":305},[53,1308,110],{"class":109},[53,1310,1296],{"class":113},[53,1312,317],{"class":109},[53,1314,1315,1317,1319,1322,1324,1326],{"class":55,"line":95},[53,1316,106],{"class":105},[53,1318,110],{"class":109},[53,1320,1321],{"class":105},"len",[53,1323,110],{"class":109},[53,1325,1296],{"class":113},[53,1327,317],{"class":109},[14,1329,1330],{},"Use them to answer simple questions:",[21,1332,1333,1336,1339],{},[24,1334,1335],{},"What is the actual value?",[24,1337,1338],{},"What type is it?",[24,1340,1341],{},"How long is it?",[152,1343,1345],{"id":1344},"faq","FAQ",[508,1347,1349],{"id":1348},"is-a-string-always-text","Is a string always text?",[14,1351,1352,1353,749],{},"Yes. In Python, a string represents text data, even if the text contains digits like ",[37,1354,181],{},[508,1356,1358,1359,941,1361,1363],{"id":1357},"what-is-the-difference-between-5-and-5-in-python","What is the difference between ",[37,1360,1028],{},[37,1362,975],{}," in Python?",[14,1365,1366,1368,1369,1371],{},[37,1367,1028],{}," is a string. ",[37,1370,975],{}," is an integer. The first is text, the second is a number.",[508,1373,1375],{"id":1374},"can-a-string-be-empty","Can a string be empty?",[14,1377,1378,1379,1381,1382,749],{},"Yes. An empty string is written as ",[37,1380,39],{}," or ",[37,1383,1384],{},"''",[508,1386,1388],{"id":1387},"do-i-have-to-use-double-quotes-for-strings","Do I have to use double quotes for strings?",[14,1390,1391],{},"No. You can use single quotes or double quotes. Both create strings.",[508,1393,1395,1396,1398],{"id":1394},"why-does-input-usually-give-me-a-string","Why does ",[37,1397,409],{}," usually give me a string?",[14,1400,1401],{},"Because user input is read as text by default. Convert it if you need a number.",[152,1403,1405],{"id":1404},"see-also","See also",[21,1407,1408,1413,1419,1429,1435,1440,1450],{},[24,1409,1410],{},[378,1411,1412],{"href":932},"Python strings explained: basics and examples",[24,1414,1415],{},[378,1416,1418],{"href":1417},"\u002Freference\u002Fpython-string-creating-a-string\u002F","Creating a string in Python",[24,1420,1421],{},[378,1422,1424,1425,1428],{"href":1423},"\u002Freference\u002Fpython-str-function-explained\u002F","Python ",[37,1426,1427],{},"str()"," function explained",[24,1430,1431],{},[378,1432,1434],{"href":1433},"\u002Fhow-to\u002Fhow-to-convert-int-to-string-in-python\u002F","How to convert int to string in Python",[24,1436,1437],{},[378,1438,1439],{"href":1128},"How to convert string to int in Python",[24,1441,1442],{},[378,1443,1445,1446,1449],{"href":1444},"\u002Freference\u002Fpython-string-replace-method\u002F","Python string ",[37,1447,1448],{},"replace()"," method",[24,1451,1452],{},[378,1453,1445,1455,1449],{"href":1454},"\u002Freference\u002Fpython-string-format-method\u002F",[37,1456,1457],{},"format()",[1459,1460,1461],"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 .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}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 .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 .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":49,"searchDepth":78,"depth":78,"links":1463},[1464,1465,1466,1467,1476,1477,1478,1479,1488],{"id":154,"depth":78,"text":155},{"id":270,"depth":78,"text":271},{"id":388,"depth":78,"text":389},{"id":502,"depth":78,"text":503,"children":1468},[1469,1471,1473,1474,1475],{"id":510,"depth":95,"text":1470},"Join text together with +",{"id":585,"depth":95,"text":1472},"Repeat text with *",{"id":629,"depth":95,"text":630},{"id":713,"depth":95,"text":714},{"id":791,"depth":95,"text":792},{"id":950,"depth":78,"text":951},{"id":1132,"depth":78,"text":1133},{"id":1161,"depth":78,"text":1162},{"id":1344,"depth":78,"text":1345,"children":1480},[1481,1482,1484,1485,1486],{"id":1348,"depth":95,"text":1349},{"id":1357,"depth":95,"text":1483},"What is the difference between \"5\" and 5 in Python?",{"id":1374,"depth":95,"text":1375},{"id":1387,"depth":95,"text":1388},{"id":1394,"depth":95,"text":1487},"Why does input() usually give me a string?",{"id":1404,"depth":78,"text":1405},"Master what is a string in python in our comprehensive Python beginner guide.","md",{},"\u002Fglossary\u002Fwhat-is-a-string-in-python",{"title":5,"description":1489},"glossary\u002Fwhat-is-a-string-in-python","Td1pXRnDFzUyxLtt-UvNN658iZV0k9uDXXrR28M2_04",1777585494128]