[{"data":1,"prerenderedAt":4545},["ShallowReactive",2],{"post-2025-07-02-python":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"tags":11,"body":14,"_type":4539,"_id":4540,"_source":4541,"_file":4542,"_stem":4543,"_extension":4544},"\u002Fblog\u002F2025-07-02-python","blog",false,"","Python-语言基础","Python语言基础：变量、数据类型、运算符、输入输出等核心语法入门。","2025-07-02",[12,13],"Python","基础",{"type":15,"children":16,"toc":4532},"root",[17,22,30,67,89,122,142,147,211,217,227,258,268,287,371,431,436,441,449,588,596,601,624,632,675,739,753,785,793,798,821,829,1001,1006,1019,1042,1063,1102,1134,1139,1178,1186,1205,1276,1281,1319,1372,1477,1482,1488,1498,1512,1520,1645,1747,1753,1758,1813,1818,1863,1877,1881,1889,1903,1907,1915,1929,1933,1940,1954,1958,1966,1980,1984,1991,2005,2009,2017,2031,2035,2043,2057,2061,2069,2092,2096,2104,2118,2122,2130,2144,2148,2156,2179,2183,2191,2197,2202,2289,2295,2300,2323,2327,2334,2357,2361,2369,2416,2420,2428,2442,2446,2454,2509,2513,2521,2576,2580,2588,2626,2630,2638,2661,2665,2673,2720,2724,2732,2738,2751,2756,2770,2775,2784,2792,2873,2887,2896,2919,2929,2952,2962,2967,2981,2986,2994,3000,3047,3070,3074,3082,3113,3117,3125,3131,3142,3165,3170,3178,3183,3222,3226,3234,3254,3293,3297,3305,3311,3323,3386,3390,3398,3469,3473,3481,3487,3500,3523,3528,3536,3575,3580,3588,3596,3602,3635,3698,3702,3710,3749,3753,3761,3807,3811,3819,3825,3830,3869,3882,3890,3895,3964,3969,3977,3990,4073,4077,4085,4093,4098,4152,4156,4164,4184,4282,4286,4294,4302,4307,4402,4407,4415,4423,4428,4514,4518,4526],{"type":18,"tag":19,"props":20,"children":21},"element","hr",{},[],{"type":18,"tag":23,"props":24,"children":26},"h3",{"id":25},"python语法特点",[27],{"type":28,"value":29},"text","Python语法特点",{"type":18,"tag":31,"props":32,"children":33},"p",{},[34,40,42,49,54,55,60,62],{"type":18,"tag":35,"props":36,"children":37},"strong",{},[38],{"type":28,"value":39},"单行注释",{"type":28,"value":41},"：",{"type":18,"tag":43,"props":44,"children":46},"font",{"color":45},"green",[47],{"type":28,"value":48},"# 注释内容",{"type":18,"tag":35,"props":50,"children":51},{},[52],{"type":28,"value":53},"多行注释",{"type":28,"value":41},{"type":18,"tag":43,"props":56,"children":57},{"color":45},[58],{"type":28,"value":59},"''' 注释内容 '''",{"type":28,"value":61}," 或 ",{"type":18,"tag":43,"props":63,"children":64},{"color":45},[65],{"type":28,"value":66},"\"\"\" 注释内容 \"\"\"",{"type":18,"tag":68,"props":69,"children":70},"blockquote",{},[71],{"type":18,"tag":31,"props":72,"children":73},{},[74,76,81,83],{"type":28,"value":75},"使用三引号作为注释时，",{"type":18,"tag":35,"props":77,"children":78},{},[79],{"type":28,"value":80},"三引号必须成对出现",{"type":28,"value":82},"，否则将出现下面报错：\n",{"type":18,"tag":43,"props":84,"children":86},{"color":85},"red",[87],{"type":28,"value":88},"SyntaxError: unterminated triple-quoted string literal",{"type":18,"tag":31,"props":90,"children":91},{},[92,94,99,101,106,108,113,115,120],{"type":28,"value":93},"Python是通过",{"type":18,"tag":35,"props":95,"children":96},{},[97],{"type":28,"value":98},"缩进",{"type":28,"value":100},"和",{"type":18,"tag":35,"props":102,"children":103},{},[104],{"type":28,"value":105},"半角冒号",{"type":28,"value":107},"区分代码之间的",{"type":18,"tag":35,"props":109,"children":110},{},[111],{"type":28,"value":112},"层次",{"type":28,"value":114},"，编码时建议严格遵循",{"type":18,"tag":35,"props":116,"children":117},{},[118],{"type":28,"value":119},"PEP8编码规范",{"type":28,"value":121},"，增加代码的可读性。",{"type":18,"tag":68,"props":123,"children":124},{},[125],{"type":18,"tag":31,"props":126,"children":127},{},[128,133,135,140],{"type":18,"tag":35,"props":129,"children":130},{},[131],{"type":28,"value":132},"同级代码的缩进量必须相同",{"type":28,"value":134},"，否则将会抛出",{"type":18,"tag":43,"props":136,"children":137},{"color":85},[138],{"type":28,"value":139},"SyntaxError",{"type":28,"value":141},"异常",{"type":18,"tag":31,"props":143,"children":144},{},[145],{"type":28,"value":146},"我了解了一些命名规范：",{"type":18,"tag":148,"props":149,"children":150},"ul",{},[151,162,172,182,192],{"type":18,"tag":152,"props":153,"children":154},"li",{},[155,160],{"type":18,"tag":35,"props":156,"children":157},{},[158],{"type":28,"value":159},"函数、类属性及方法、模块名",{"type":28,"value":161},"：全小写且尽量短小，可使用下划线",{"type":18,"tag":152,"props":163,"children":164},{},[165,170],{"type":18,"tag":35,"props":166,"children":167},{},[168],{"type":28,"value":169},"包名",{"type":28,"value":171},"：全小写且尽量短小，避免使用下划线",{"type":18,"tag":152,"props":173,"children":174},{},[175,180],{"type":18,"tag":35,"props":176,"children":177},{},[178],{"type":28,"value":179},"类名",{"type":28,"value":181},"：采用单词首字母大写的风格",{"type":18,"tag":152,"props":183,"children":184},{},[185,190],{"type":18,"tag":35,"props":186,"children":187},{},[188],{"type":28,"value":189},"模块内部的类名",{"type":28,"value":191},"：采用下划线+首字母大写的类名",{"type":18,"tag":152,"props":193,"children":194},{},[195,197,202,204,209],{"type":28,"value":196},"使用",{"type":18,"tag":35,"props":198,"children":199},{},[200],{"type":28,"value":201},"双下划线开头",{"type":28,"value":203},"的实例变量或方法是",{"type":18,"tag":35,"props":205,"children":206},{},[207],{"type":28,"value":208},"类私有",{"type":28,"value":210},"的",{"type":18,"tag":23,"props":212,"children":214},{"id":213},"python中的变量",[215],{"type":28,"value":216},"Python中的变量",{"type":18,"tag":31,"props":218,"children":219},{},[220,225],{"type":18,"tag":35,"props":221,"children":222},{},[223],{"type":28,"value":224},"保留字",{"type":28,"value":226},"：被Python赋予特定意义的单词，这些单词不能充当标识符。可使用下面语句查询保留字的内容：",{"type":18,"tag":228,"props":229,"children":233},"pre",{"code":230,"language":231,"meta":7,"className":232,"style":7},"import keyword\nprint(keyword.kwlist)\n","python","language-python shiki shiki-themes github-dark",[234],{"type":18,"tag":235,"props":236,"children":237},"code",{"__ignoreMap":7},[238,249],{"type":18,"tag":239,"props":240,"children":243},"span",{"class":241,"line":242},"line",1,[244],{"type":18,"tag":239,"props":245,"children":246},{},[247],{"type":28,"value":248},"import keyword\n",{"type":18,"tag":239,"props":250,"children":252},{"class":241,"line":251},2,[253],{"type":18,"tag":239,"props":254,"children":255},{},[256],{"type":28,"value":257},"print(keyword.kwlist)\n",{"type":18,"tag":31,"props":259,"children":260},{},[261,266],{"type":18,"tag":35,"props":262,"children":263},{},[264],{"type":28,"value":265},"标识符",{"type":28,"value":267},"：标识变量、函数、类、模块和其他对象的名称，其命名规则如下：",{"type":18,"tag":269,"props":270,"children":271},"ol",{},[272,277,282],{"type":18,"tag":152,"props":273,"children":274},{},[275],{"type":28,"value":276},"由字母、数字、下划线组成",{"type":18,"tag":152,"props":278,"children":279},{},[280],{"type":28,"value":281},"不能以数字开头",{"type":18,"tag":152,"props":283,"children":284},{},[285],{"type":28,"value":286},"区分大小写",{"type":18,"tag":31,"props":288,"children":289},{},[290,292,297,299,304,306,312,314,320,322,327,329,335,337,343,345,351,356,358,364,369],{"type":28,"value":291},"Python是一种",{"type":18,"tag":35,"props":293,"children":294},{},[295],{"type":28,"value":296},"动态类型",{"type":28,"value":298},"的语言，变量的类型可以随时变化。为",{"type":18,"tag":35,"props":300,"children":301},{},[302],{"type":28,"value":303},"变量赋值",{"type":28,"value":305},"可以通过",{"type":18,"tag":235,"props":307,"children":309},{"className":308},[],[310],{"type":28,"value":311},"=",{"type":28,"value":313},"实现，例如：",{"type":18,"tag":235,"props":315,"children":317},{"className":316},[],[318],{"type":28,"value":319},"my_name = \"WuChen\"",{"type":28,"value":321}," ；若要",{"type":18,"tag":35,"props":323,"children":324},{},[325],{"type":28,"value":326},"同时输出多份内容",{"type":28,"value":328},"，则可以在相邻两内容用",{"type":18,"tag":235,"props":330,"children":332},{"className":331},[],[333],{"type":28,"value":334},",",{"type":28,"value":336},"间隔，例如：",{"type":18,"tag":235,"props":338,"children":340},{"className":339},[],[341],{"type":28,"value":342},"print(value1,value2,value3,...)",{"type":28,"value":344},"；在python中可以使用内置函数",{"type":18,"tag":235,"props":346,"children":348},{"className":347},[],[349],{"type":28,"value":350},"type(被查找类型的数据)",{"type":18,"tag":35,"props":352,"children":353},{},[354],{"type":28,"value":355},"返回变量类型",{"type":28,"value":357},"；可以使用内置函数",{"type":18,"tag":235,"props":359,"children":361},{"className":360},[],[362],{"type":28,"value":363},"id(被查找地址的值名称)",{"type":18,"tag":35,"props":365,"children":366},{},[367],{"type":28,"value":368},"返回变量所指的内存地址",{"type":28,"value":370},"。",{"type":18,"tag":228,"props":372,"children":374},{"code":373,"language":231,"meta":7,"className":232,"style":7},"name = \"Liu\"\nID = 2048\nprint(type(name),type(ID))            # \u003Cclass 'str'> \u003Cclass 'int'>\n\nnum1 = num2 = 1024\nprint(id(num1),id(num2))     # 输出内容为：2536300786608 2536300786608\n",[375],{"type":18,"tag":235,"props":376,"children":377},{"__ignoreMap":7},[378,386,394,403,413,422],{"type":18,"tag":239,"props":379,"children":380},{"class":241,"line":242},[381],{"type":18,"tag":239,"props":382,"children":383},{},[384],{"type":28,"value":385},"name = \"Liu\"\n",{"type":18,"tag":239,"props":387,"children":388},{"class":241,"line":251},[389],{"type":18,"tag":239,"props":390,"children":391},{},[392],{"type":28,"value":393},"ID = 2048\n",{"type":18,"tag":239,"props":395,"children":397},{"class":241,"line":396},3,[398],{"type":18,"tag":239,"props":399,"children":400},{},[401],{"type":28,"value":402},"print(type(name),type(ID))            # \u003Cclass 'str'> \u003Cclass 'int'>\n",{"type":18,"tag":239,"props":404,"children":406},{"class":241,"line":405},4,[407],{"type":18,"tag":239,"props":408,"children":410},{"emptyLinePlaceholder":409},true,[411],{"type":28,"value":412},"\n",{"type":18,"tag":239,"props":414,"children":416},{"class":241,"line":415},5,[417],{"type":18,"tag":239,"props":418,"children":419},{},[420],{"type":28,"value":421},"num1 = num2 = 1024\n",{"type":18,"tag":239,"props":423,"children":425},{"class":241,"line":424},6,[426],{"type":18,"tag":239,"props":427,"children":428},{},[429],{"type":28,"value":430},"print(id(num1),id(num2))     # 输出内容为：2536300786608 2536300786608\n",{"type":18,"tag":23,"props":432,"children":434},{"id":433},"基本数据类型",[435],{"type":28,"value":433},{"type":18,"tag":31,"props":437,"children":438},{},[439],{"type":28,"value":440},"python中的变量无类型，但变量所存储的数据具有类型",{"type":18,"tag":31,"props":442,"children":443},{},[444],{"type":18,"tag":35,"props":445,"children":446},{},[447],{"type":28,"value":448},"数字型",{"type":18,"tag":450,"props":451,"children":452},"table",{},[453,483],{"type":18,"tag":454,"props":455,"children":456},"thead",{},[457],{"type":18,"tag":458,"props":459,"children":460},"tr",{},[461,468,473,478],{"type":18,"tag":462,"props":463,"children":465},"th",{"align":464},"center",[466],{"type":28,"value":467},"整数",{"type":18,"tag":462,"props":469,"children":470},{"align":464},[471],{"type":28,"value":472},"组成",{"type":18,"tag":462,"props":474,"children":475},{"align":464},[476],{"type":28,"value":477},"开头",{"type":18,"tag":462,"props":479,"children":480},{"align":464},[481],{"type":28,"value":482},"示例",{"type":18,"tag":484,"props":485,"children":486},"tbody",{},[487,511,534,557],{"type":18,"tag":458,"props":488,"children":489},{},[490,496,501,506],{"type":18,"tag":491,"props":492,"children":493},"td",{"align":464},[494],{"type":28,"value":495},"二进制",{"type":18,"tag":491,"props":497,"children":498},{"align":464},[499],{"type":28,"value":500},"0或1",{"type":18,"tag":491,"props":502,"children":503},{"align":464},[504],{"type":28,"value":505},"0b \u002F 0B",{"type":18,"tag":491,"props":507,"children":508},{"align":464},[509],{"type":28,"value":510},"0b1010011",{"type":18,"tag":458,"props":512,"children":513},{},[514,519,524,529],{"type":18,"tag":491,"props":515,"children":516},{"align":464},[517],{"type":28,"value":518},"八进制",{"type":18,"tag":491,"props":520,"children":521},{"align":464},[522],{"type":28,"value":523},"0~7",{"type":18,"tag":491,"props":525,"children":526},{"align":464},[527],{"type":28,"value":528},"0o \u002F 0O",{"type":18,"tag":491,"props":530,"children":531},{"align":464},[532],{"type":28,"value":533},"-0o123",{"type":18,"tag":458,"props":535,"children":536},{},[537,542,547,552],{"type":18,"tag":491,"props":538,"children":539},{"align":464},[540],{"type":28,"value":541},"十进制",{"type":18,"tag":491,"props":543,"children":544},{"align":464},[545],{"type":28,"value":546},"0~9",{"type":18,"tag":491,"props":548,"children":549},{"align":464},[550],{"type":28,"value":551},"---",{"type":18,"tag":491,"props":553,"children":554},{"align":464},[555],{"type":28,"value":556},"83",{"type":18,"tag":458,"props":558,"children":559},{},[560,565,578,583],{"type":18,"tag":491,"props":561,"children":562},{"align":464},[563],{"type":28,"value":564},"十六进制",{"type":18,"tag":491,"props":566,"children":567},{"align":464},[568,570,576],{"type":28,"value":569},"0",{"type":18,"tag":571,"props":572,"children":573},"del",{},[574],{"type":28,"value":575},"9和A",{"type":28,"value":577},"F",{"type":18,"tag":491,"props":579,"children":580},{"align":464},[581],{"type":28,"value":582},"0x \u002F 0X",{"type":18,"tag":491,"props":584,"children":585},{"align":464},[586],{"type":28,"value":587},"0x53",{"type":18,"tag":68,"props":589,"children":590},{},[591],{"type":18,"tag":31,"props":592,"children":593},{},[594],{"type":28,"value":595},"不能以“0”作为十进制数的开头（0除外）",{"type":18,"tag":31,"props":597,"children":598},{},[599],{"type":28,"value":600},"浮点数由整数部分和小数部分组成，也可以使用科学计数法表示。在使用浮点数进行计算时，有一个特例体现了小数位数不确定的情况，特例代码如下：",{"type":18,"tag":228,"props":602,"children":604},{"code":603,"language":231,"meta":7,"className":232,"style":7},"result = 0.1 + 0.2\nprint(result)   # 输出结果为0.30000000000000004\n",[605],{"type":18,"tag":235,"props":606,"children":607},{"__ignoreMap":7},[608,616],{"type":18,"tag":239,"props":609,"children":610},{"class":241,"line":242},[611],{"type":18,"tag":239,"props":612,"children":613},{},[614],{"type":28,"value":615},"result = 0.1 + 0.2\n",{"type":18,"tag":239,"props":617,"children":618},{"class":241,"line":251},[619],{"type":18,"tag":239,"props":620,"children":621},{},[622],{"type":28,"value":623},"print(result)   # 输出结果为0.30000000000000004\n",{"type":18,"tag":31,"props":625,"children":626},{},[627],{"type":18,"tag":35,"props":628,"children":629},{},[630],{"type":28,"value":631},"字符串型",{"type":18,"tag":31,"props":633,"children":634},{},[635,637,643,645,651,653,659,661,667,669,674],{"type":28,"value":636},"通常使用单引号",{"type":18,"tag":235,"props":638,"children":640},{"className":639},[],[641],{"type":28,"value":642},"' '",{"type":28,"value":644},"、双引号",{"type":18,"tag":235,"props":646,"children":648},{"className":647},[],[649],{"type":28,"value":650},"\" \"",{"type":28,"value":652},"或者三引号",{"type":18,"tag":235,"props":654,"children":656},{"className":655},[],[657],{"type":28,"value":658},"\"\"\" \"\"\"",{"type":28,"value":660},"或",{"type":18,"tag":235,"props":662,"children":664},{"className":663},[],[665],{"type":28,"value":666},"''' '''",{"type":28,"value":668},"括起来，其中单引号和双引号的字符序列必须在一行上。需要表示复杂的字符串时，还可以进行引号嵌套，但是，",{"type":18,"tag":43,"props":670,"children":671},{"color":85},[672],{"type":28,"value":673},"字符串开始和结尾使用的引号形式必须一致",{"type":28,"value":370},{"type":18,"tag":228,"props":676,"children":678},{"code":677,"language":231,"meta":7,"className":232,"style":7},"# 使用单引号和双引号字符序列都必须在同一行\ntitle = '我的座右铭'\nlabel = \"努力学习，顶峰相见\"\n# 三引号字符串序列何以分布在多行上\nentry = \"\"\"书山有路勤为径，\n学海无涯苦作舟\"\"\"\nprint(title,'\\n',label,'\\n',entry)\n",[679],{"type":18,"tag":235,"props":680,"children":681},{"__ignoreMap":7},[682,690,698,706,714,722,730],{"type":18,"tag":239,"props":683,"children":684},{"class":241,"line":242},[685],{"type":18,"tag":239,"props":686,"children":687},{},[688],{"type":28,"value":689},"# 使用单引号和双引号字符序列都必须在同一行\n",{"type":18,"tag":239,"props":691,"children":692},{"class":241,"line":251},[693],{"type":18,"tag":239,"props":694,"children":695},{},[696],{"type":28,"value":697},"title = '我的座右铭'\n",{"type":18,"tag":239,"props":699,"children":700},{"class":241,"line":396},[701],{"type":18,"tag":239,"props":702,"children":703},{},[704],{"type":28,"value":705},"label = \"努力学习，顶峰相见\"\n",{"type":18,"tag":239,"props":707,"children":708},{"class":241,"line":405},[709],{"type":18,"tag":239,"props":710,"children":711},{},[712],{"type":28,"value":713},"# 三引号字符串序列何以分布在多行上\n",{"type":18,"tag":239,"props":715,"children":716},{"class":241,"line":415},[717],{"type":18,"tag":239,"props":718,"children":719},{},[720],{"type":28,"value":721},"entry = \"\"\"书山有路勤为径，\n",{"type":18,"tag":239,"props":723,"children":724},{"class":241,"line":424},[725],{"type":18,"tag":239,"props":726,"children":727},{},[728],{"type":28,"value":729},"学海无涯苦作舟\"\"\"\n",{"type":18,"tag":239,"props":731,"children":733},{"class":241,"line":732},7,[734],{"type":18,"tag":239,"props":735,"children":736},{},[737],{"type":28,"value":738},"print(title,'\\n',label,'\\n',entry)\n",{"type":18,"tag":68,"props":740,"children":741},{},[742],{"type":18,"tag":31,"props":743,"children":744},{},[745,751],{"type":18,"tag":235,"props":746,"children":748},{"className":747},[],[749],{"type":28,"value":750},"str()",{"type":28,"value":752},"函数用于将数值转换为字符串。",{"type":18,"tag":68,"props":754,"children":755},{},[756],{"type":18,"tag":31,"props":757,"children":758},{},[759,761,767,769,775,777,783],{"type":28,"value":760},"在字符串定界符的前面加上字母",{"type":18,"tag":235,"props":762,"children":764},{"className":763},[],[765],{"type":28,"value":766},"r",{"type":28,"value":768},"或者",{"type":18,"tag":235,"props":770,"children":772},{"className":771},[],[773],{"type":28,"value":774},"R",{"type":28,"value":776},"，那么该字符串将原样输出，其中的转义字符将不再进行转义输出，例如：",{"type":18,"tag":235,"props":778,"children":780},{"className":779},[],[781],{"type":28,"value":782},"print(r\"失望之酒\\n机会之杯\")",{"type":28,"value":784},"将直接输出“失望之酒\\n机会之杯”。",{"type":18,"tag":31,"props":786,"children":787},{},[788],{"type":18,"tag":35,"props":789,"children":790},{},[791],{"type":28,"value":792},"布尔类型",{"type":18,"tag":31,"props":794,"children":795},{},[796],{"type":28,"value":797},"用来表示真或假的值，所有的Python对象都可以进行真值测试。True 为 1，False 为 0\n其中下面的4种情况为假：",{"type":18,"tag":148,"props":799,"children":800},{},[801,806,811,816],{"type":18,"tag":152,"props":802,"children":803},{},[804],{"type":28,"value":805},"False或None",{"type":18,"tag":152,"props":807,"children":808},{},[809],{"type":28,"value":810},"数值中的零，包括0、0.0、虚数0",{"type":18,"tag":152,"props":812,"children":813},{},[814],{"type":28,"value":815},"空序列，包括字符串、空元组、空列表、空字典",{"type":18,"tag":152,"props":817,"children":818},{},[819],{"type":28,"value":820},"自定义对象的实例，该对象的__bool__方法返回False，或者__len__方法返回0",{"type":18,"tag":31,"props":822,"children":823},{},[824],{"type":18,"tag":35,"props":825,"children":826},{},[827],{"type":28,"value":828},"数据类型转换",{"type":18,"tag":450,"props":830,"children":831},{},[832,848],{"type":18,"tag":454,"props":833,"children":834},{},[835],{"type":18,"tag":458,"props":836,"children":837},{},[838,843],{"type":18,"tag":462,"props":839,"children":840},{"align":464},[841],{"type":28,"value":842},"函数",{"type":18,"tag":462,"props":844,"children":845},{"align":464},[846],{"type":28,"value":847},"作用",{"type":18,"tag":484,"props":849,"children":850},{},[851,864,877,897,910,923,936,949,962,975,988],{"type":18,"tag":458,"props":852,"children":853},{},[854,859],{"type":18,"tag":491,"props":855,"children":856},{"align":464},[857],{"type":28,"value":858},"int(x)",{"type":18,"tag":491,"props":860,"children":861},{"align":464},[862],{"type":28,"value":863},"将x转换成整数类型",{"type":18,"tag":458,"props":865,"children":866},{},[867,872],{"type":18,"tag":491,"props":868,"children":869},{"align":464},[870],{"type":28,"value":871},"float(x)",{"type":18,"tag":491,"props":873,"children":874},{"align":464},[875],{"type":28,"value":876},"将x转换成浮点数类型",{"type":18,"tag":458,"props":878,"children":879},{},[880,892],{"type":18,"tag":491,"props":881,"children":882},{"align":464},[883,885,890],{"type":28,"value":884},"complex(real",{"type":18,"tag":239,"props":886,"children":887},{},[888],{"type":28,"value":889},",imag",{"type":28,"value":891},")",{"type":18,"tag":491,"props":893,"children":894},{"align":464},[895],{"type":28,"value":896},"创建一个复数",{"type":18,"tag":458,"props":898,"children":899},{},[900,905],{"type":18,"tag":491,"props":901,"children":902},{"align":464},[903],{"type":28,"value":904},"str(x)",{"type":18,"tag":491,"props":906,"children":907},{"align":464},[908],{"type":28,"value":909},"将x转换为字符串",{"type":18,"tag":458,"props":911,"children":912},{},[913,918],{"type":18,"tag":491,"props":914,"children":915},{"align":464},[916],{"type":28,"value":917},"repr(x)",{"type":18,"tag":491,"props":919,"children":920},{"align":464},[921],{"type":28,"value":922},"将x转换为表达式字符串",{"type":18,"tag":458,"props":924,"children":925},{},[926,931],{"type":18,"tag":491,"props":927,"children":928},{"align":464},[929],{"type":28,"value":930},"eval(str)",{"type":18,"tag":491,"props":932,"children":933},{"align":464},[934],{"type":28,"value":935},"计算在字符串中的有效Python表达式，并返回一个对象",{"type":18,"tag":458,"props":937,"children":938},{},[939,944],{"type":18,"tag":491,"props":940,"children":941},{"align":464},[942],{"type":28,"value":943},"chr(x)",{"type":18,"tag":491,"props":945,"children":946},{"align":464},[947],{"type":28,"value":948},"将整数x转换为一个字符",{"type":18,"tag":458,"props":950,"children":951},{},[952,957],{"type":18,"tag":491,"props":953,"children":954},{"align":464},[955],{"type":28,"value":956},"ord(x)",{"type":18,"tag":491,"props":958,"children":959},{"align":464},[960],{"type":28,"value":961},"将一个字符x转换为它对应的整数值",{"type":18,"tag":458,"props":963,"children":964},{},[965,970],{"type":18,"tag":491,"props":966,"children":967},{"align":464},[968],{"type":28,"value":969},"hex(x)",{"type":18,"tag":491,"props":971,"children":972},{"align":464},[973],{"type":28,"value":974},"将一个整数x转换为一个十六进制的字符串",{"type":18,"tag":458,"props":976,"children":977},{},[978,983],{"type":18,"tag":491,"props":979,"children":980},{"align":464},[981],{"type":28,"value":982},"oct(x)",{"type":18,"tag":491,"props":984,"children":985},{"align":464},[986],{"type":28,"value":987},"将一个整数x转换为一个八进制的字符串",{"type":18,"tag":458,"props":989,"children":990},{},[991,996],{"type":18,"tag":491,"props":992,"children":993},{"align":464},[994],{"type":28,"value":995},"bin(x)",{"type":18,"tag":491,"props":997,"children":998},{"align":464},[999],{"type":28,"value":1000},"将一个整数x转换为一个二进制的字符串",{"type":18,"tag":23,"props":1002,"children":1004},{"id":1003},"基本输入和输出",[1005],{"type":28,"value":1003},{"type":18,"tag":31,"props":1007,"children":1008},{},[1009,1011,1017],{"type":28,"value":1010},"Python中可以通过内置函数",{"type":18,"tag":235,"props":1012,"children":1014},{"className":1013},[],[1015],{"type":28,"value":1016},"input()",{"type":28,"value":1018},"可以接收用户通过键盘输入的内容，基本用法如下：",{"type":18,"tag":228,"props":1020,"children":1022},{"code":1021,"language":231,"meta":7,"className":232,"style":7},"entry = input()\nvalue = int(input())  # 若想要接收整型，则需要对其进行整型转换\n",[1023],{"type":18,"tag":235,"props":1024,"children":1025},{"__ignoreMap":7},[1026,1034],{"type":18,"tag":239,"props":1027,"children":1028},{"class":241,"line":242},[1029],{"type":18,"tag":239,"props":1030,"children":1031},{},[1032],{"type":28,"value":1033},"entry = input()\n",{"type":18,"tag":239,"props":1035,"children":1036},{"class":241,"line":251},[1037],{"type":18,"tag":239,"props":1038,"children":1039},{},[1040],{"type":28,"value":1041},"value = int(input())  # 若想要接收整型，则需要对其进行整型转换\n",{"type":18,"tag":31,"props":1043,"children":1044},{},[1045,1047,1053,1055,1061],{"type":28,"value":1046},"默认情况下，使用内置函数",{"type":18,"tag":235,"props":1048,"children":1050},{"className":1049},[],[1051],{"type":28,"value":1052},"print()",{"type":28,"value":1054},"可以将结果输出在标准控制台上，语法为：",{"type":18,"tag":235,"props":1056,"children":1058},{"className":1057},[],[1059],{"type":28,"value":1060},"print(输出内容)",{"type":28,"value":1062},"；输出内容可以是数字和字符串，这类内容将直接输出，也可以是包含运算符的表达式，此类内容将计算结果输出。",{"type":18,"tag":228,"props":1064,"children":1066},{"code":1065,"language":231,"meta":7,"className":232,"style":7},"name = \"张三\"\nprint(\"我的名字是\" + name)\n'''print(\"变量1\" if 条件 else \"变量2\") '''\nprint(a if a>b else b)  # 条件为真返回a，否则返回b\n",[1067],{"type":18,"tag":235,"props":1068,"children":1069},{"__ignoreMap":7},[1070,1078,1086,1094],{"type":18,"tag":239,"props":1071,"children":1072},{"class":241,"line":242},[1073],{"type":18,"tag":239,"props":1074,"children":1075},{},[1076],{"type":28,"value":1077},"name = \"张三\"\n",{"type":18,"tag":239,"props":1079,"children":1080},{"class":241,"line":251},[1081],{"type":18,"tag":239,"props":1082,"children":1083},{},[1084],{"type":28,"value":1085},"print(\"我的名字是\" + name)\n",{"type":18,"tag":239,"props":1087,"children":1088},{"class":241,"line":396},[1089],{"type":18,"tag":239,"props":1090,"children":1091},{},[1092],{"type":28,"value":1093},"'''print(\"变量1\" if 条件 else \"变量2\") '''\n",{"type":18,"tag":239,"props":1095,"children":1096},{"class":241,"line":405},[1097],{"type":18,"tag":239,"props":1098,"children":1099},{},[1100],{"type":28,"value":1101},"print(a if a>b else b)  # 条件为真返回a，否则返回b\n",{"type":18,"tag":68,"props":1103,"children":1104},{},[1105],{"type":18,"tag":31,"props":1106,"children":1107},{},[1108,1110,1116,1118,1124,1126,1132],{"type":28,"value":1109},"Python中每一条",{"type":18,"tag":235,"props":1111,"children":1113},{"className":1112},[],[1114],{"type":28,"value":1115},"print()语句",{"type":28,"value":1117},"输出后都会自动进行换行，若不想让其换行，可以使用",{"type":18,"tag":235,"props":1119,"children":1121},{"className":1120},[],[1122],{"type":28,"value":1123},"end=''",{"type":28,"value":1125},"来指定结束符，例如：",{"type":18,"tag":235,"props":1127,"children":1129},{"className":1128},[],[1130],{"type":28,"value":1131},"print(\"Hello World\",end=\" \")",{"type":28,"value":1133}," 表示输出Hello World并且以空格作为结束符。",{"type":18,"tag":31,"props":1135,"children":1136},{},[1137],{"type":28,"value":1138},"在输出时，还可以把结果输出到指定文件中。例如：",{"type":18,"tag":228,"props":1140,"children":1142},{"code":1141,"language":231,"meta":7,"className":232,"style":7},"# 将“Hello World”输出到指定的文件“D:\u002F\u002FMyfile\u002Ftxt\u002Fdemo.txt”中\nfp = open(\"D:\u002F\u002FMyfile\u002Ftxt\u002Fdemo.txt\",\"a+\")      # 打开文件\nprint(\"Hello World\",file = fp)                 # 输出到文件\nfp.close()                                     # 关闭文件\n",[1143],{"type":18,"tag":235,"props":1144,"children":1145},{"__ignoreMap":7},[1146,1154,1162,1170],{"type":18,"tag":239,"props":1147,"children":1148},{"class":241,"line":242},[1149],{"type":18,"tag":239,"props":1150,"children":1151},{},[1152],{"type":28,"value":1153},"# 将“Hello World”输出到指定的文件“D:\u002F\u002FMyfile\u002Ftxt\u002Fdemo.txt”中\n",{"type":18,"tag":239,"props":1155,"children":1156},{"class":241,"line":251},[1157],{"type":18,"tag":239,"props":1158,"children":1159},{},[1160],{"type":28,"value":1161},"fp = open(\"D:\u002F\u002FMyfile\u002Ftxt\u002Fdemo.txt\",\"a+\")      # 打开文件\n",{"type":18,"tag":239,"props":1163,"children":1164},{"class":241,"line":396},[1165],{"type":18,"tag":239,"props":1166,"children":1167},{},[1168],{"type":28,"value":1169},"print(\"Hello World\",file = fp)                 # 输出到文件\n",{"type":18,"tag":239,"props":1171,"children":1172},{"class":241,"line":405},[1173],{"type":18,"tag":239,"props":1174,"children":1175},{},[1176],{"type":28,"value":1177},"fp.close()                                     # 关闭文件\n",{"type":18,"tag":31,"props":1179,"children":1180},{},[1181],{"type":18,"tag":35,"props":1182,"children":1183},{},[1184],{"type":28,"value":1185},"pprint()格式化输出函数",{"type":18,"tag":31,"props":1187,"children":1188},{},[1189,1195,1197,1203],{"type":18,"tag":235,"props":1190,"children":1192},{"className":1191},[],[1193],{"type":28,"value":1194},"pprint模块",{"type":28,"value":1196},"提供的",{"type":18,"tag":235,"props":1198,"children":1200},{"className":1199},[],[1201],{"type":28,"value":1202},"pprint()函数",{"type":28,"value":1204},"，该函数全称 data pretty printer ，可以将输出的结果变得更加美观。",{"type":18,"tag":228,"props":1206,"children":1208},{"code":1207,"language":231,"meta":7,"className":232,"style":7},"# 使用pprint()函数输出数据时，需要先导入pprint模块中的pprint()函数\nfrom pprint import pprint\n\ndic = {\n\"张三\":{\"age\":\"18\",\"sex\":\"boy\",\"address\":\"TianJin\"},\n\"李四\":{\"age\":\"19\",\"sex\":\"girl\",\"address\":\"BeiJing\"},\n\"王五\":{\"age\":\"20\",\"sex\":\"boy\",\"address\":\"HeNan\"}\n}\n",[1209],{"type":18,"tag":235,"props":1210,"children":1211},{"__ignoreMap":7},[1212,1220,1228,1235,1243,1251,1259,1267],{"type":18,"tag":239,"props":1213,"children":1214},{"class":241,"line":242},[1215],{"type":18,"tag":239,"props":1216,"children":1217},{},[1218],{"type":28,"value":1219},"# 使用pprint()函数输出数据时，需要先导入pprint模块中的pprint()函数\n",{"type":18,"tag":239,"props":1221,"children":1222},{"class":241,"line":251},[1223],{"type":18,"tag":239,"props":1224,"children":1225},{},[1226],{"type":28,"value":1227},"from pprint import pprint\n",{"type":18,"tag":239,"props":1229,"children":1230},{"class":241,"line":396},[1231],{"type":18,"tag":239,"props":1232,"children":1233},{"emptyLinePlaceholder":409},[1234],{"type":28,"value":412},{"type":18,"tag":239,"props":1236,"children":1237},{"class":241,"line":405},[1238],{"type":18,"tag":239,"props":1239,"children":1240},{},[1241],{"type":28,"value":1242},"dic = {\n",{"type":18,"tag":239,"props":1244,"children":1245},{"class":241,"line":415},[1246],{"type":18,"tag":239,"props":1247,"children":1248},{},[1249],{"type":28,"value":1250},"\"张三\":{\"age\":\"18\",\"sex\":\"boy\",\"address\":\"TianJin\"},\n",{"type":18,"tag":239,"props":1252,"children":1253},{"class":241,"line":424},[1254],{"type":18,"tag":239,"props":1255,"children":1256},{},[1257],{"type":28,"value":1258},"\"李四\":{\"age\":\"19\",\"sex\":\"girl\",\"address\":\"BeiJing\"},\n",{"type":18,"tag":239,"props":1260,"children":1261},{"class":241,"line":732},[1262],{"type":18,"tag":239,"props":1263,"children":1264},{},[1265],{"type":28,"value":1266},"\"王五\":{\"age\":\"20\",\"sex\":\"boy\",\"address\":\"HeNan\"}\n",{"type":18,"tag":239,"props":1268,"children":1270},{"class":241,"line":1269},8,[1271],{"type":18,"tag":239,"props":1272,"children":1273},{},[1274],{"type":28,"value":1275},"}\n",{"type":18,"tag":31,"props":1277,"children":1278},{},[1279],{"type":28,"value":1280},"以上我定义了一个嵌套类型的字典，接下来我分别使用不同的方式进行输出，看看他们的效果：",{"type":18,"tag":228,"props":1282,"children":1284},{"code":1283,"language":231,"meta":7,"className":232,"style":7},"print(dic)  # 默认输出\n\"\"\"\n{'张三': {'age': '18', 'sex': 'boy', 'address': 'TianJin'}, '李四': {'age': '19', 'sex': 'girl', 'address': 'BeiJing'}, '王五': {'age': '20', 'sex': 'boy', 'address': 'HeNan'}}\n\"\"\"\n",[1285],{"type":18,"tag":235,"props":1286,"children":1287},{"__ignoreMap":7},[1288,1296,1304,1312],{"type":18,"tag":239,"props":1289,"children":1290},{"class":241,"line":242},[1291],{"type":18,"tag":239,"props":1292,"children":1293},{},[1294],{"type":28,"value":1295},"print(dic)  # 默认输出\n",{"type":18,"tag":239,"props":1297,"children":1298},{"class":241,"line":251},[1299],{"type":18,"tag":239,"props":1300,"children":1301},{},[1302],{"type":28,"value":1303},"\"\"\"\n",{"type":18,"tag":239,"props":1305,"children":1306},{"class":241,"line":396},[1307],{"type":18,"tag":239,"props":1308,"children":1309},{},[1310],{"type":28,"value":1311},"{'张三': {'age': '18', 'sex': 'boy', 'address': 'TianJin'}, '李四': {'age': '19', 'sex': 'girl', 'address': 'BeiJing'}, '王五': {'age': '20', 'sex': 'boy', 'address': 'HeNan'}}\n",{"type":18,"tag":239,"props":1313,"children":1314},{"class":241,"line":405},[1315],{"type":18,"tag":239,"props":1316,"children":1317},{},[1318],{"type":28,"value":1303},{"type":18,"tag":228,"props":1320,"children":1322},{"code":1321,"language":231,"meta":7,"className":232,"style":7},"pprint(dic)  # 默认结构化输出\n\"\"\"\n{'张三': {'address': 'TianJin', 'age': '18', 'sex': 'boy'},\n '李四': {'address': 'BeiJing', 'age': '19', 'sex': 'girl'},\n '王五': {'address': 'HeNan', 'age': '20', 'sex': 'boy'}}\n\"\"\"\n",[1323],{"type":18,"tag":235,"props":1324,"children":1325},{"__ignoreMap":7},[1326,1334,1341,1349,1357,1365],{"type":18,"tag":239,"props":1327,"children":1328},{"class":241,"line":242},[1329],{"type":18,"tag":239,"props":1330,"children":1331},{},[1332],{"type":28,"value":1333},"pprint(dic)  # 默认结构化输出\n",{"type":18,"tag":239,"props":1335,"children":1336},{"class":241,"line":251},[1337],{"type":18,"tag":239,"props":1338,"children":1339},{},[1340],{"type":28,"value":1303},{"type":18,"tag":239,"props":1342,"children":1343},{"class":241,"line":396},[1344],{"type":18,"tag":239,"props":1345,"children":1346},{},[1347],{"type":28,"value":1348},"{'张三': {'address': 'TianJin', 'age': '18', 'sex': 'boy'},\n",{"type":18,"tag":239,"props":1350,"children":1351},{"class":241,"line":405},[1352],{"type":18,"tag":239,"props":1353,"children":1354},{},[1355],{"type":28,"value":1356}," '李四': {'address': 'BeiJing', 'age': '19', 'sex': 'girl'},\n",{"type":18,"tag":239,"props":1358,"children":1359},{"class":241,"line":415},[1360],{"type":18,"tag":239,"props":1361,"children":1362},{},[1363],{"type":28,"value":1364}," '王五': {'address': 'HeNan', 'age': '20', 'sex': 'boy'}}\n",{"type":18,"tag":239,"props":1366,"children":1367},{"class":241,"line":424},[1368],{"type":18,"tag":239,"props":1369,"children":1370},{},[1371],{"type":28,"value":1303},{"type":18,"tag":228,"props":1373,"children":1375},{"code":1374,"language":231,"meta":7,"className":232,"style":7},"pprint(dic, width = 40)  # 在结构化输出的同时设置输出时每行的最大字符数\n\"\"\"\n{'张三': {'address': 'TianJin',\n        'age': '18',\n        'sex': 'boy'},\n '李四': {'address': 'BeiJing',\n        'age': '19',\n        'sex': 'girl'},\n '王五': {'address': 'HeNan',\n        'age': '20',\n        'sex': 'boy'}}\n\"\"\"\n",[1376],{"type":18,"tag":235,"props":1377,"children":1378},{"__ignoreMap":7},[1379,1387,1394,1402,1410,1418,1426,1434,1442,1451,1460,1469],{"type":18,"tag":239,"props":1380,"children":1381},{"class":241,"line":242},[1382],{"type":18,"tag":239,"props":1383,"children":1384},{},[1385],{"type":28,"value":1386},"pprint(dic, width = 40)  # 在结构化输出的同时设置输出时每行的最大字符数\n",{"type":18,"tag":239,"props":1388,"children":1389},{"class":241,"line":251},[1390],{"type":18,"tag":239,"props":1391,"children":1392},{},[1393],{"type":28,"value":1303},{"type":18,"tag":239,"props":1395,"children":1396},{"class":241,"line":396},[1397],{"type":18,"tag":239,"props":1398,"children":1399},{},[1400],{"type":28,"value":1401},"{'张三': {'address': 'TianJin',\n",{"type":18,"tag":239,"props":1403,"children":1404},{"class":241,"line":405},[1405],{"type":18,"tag":239,"props":1406,"children":1407},{},[1408],{"type":28,"value":1409},"        'age': '18',\n",{"type":18,"tag":239,"props":1411,"children":1412},{"class":241,"line":415},[1413],{"type":18,"tag":239,"props":1414,"children":1415},{},[1416],{"type":28,"value":1417},"        'sex': 'boy'},\n",{"type":18,"tag":239,"props":1419,"children":1420},{"class":241,"line":424},[1421],{"type":18,"tag":239,"props":1422,"children":1423},{},[1424],{"type":28,"value":1425}," '李四': {'address': 'BeiJing',\n",{"type":18,"tag":239,"props":1427,"children":1428},{"class":241,"line":732},[1429],{"type":18,"tag":239,"props":1430,"children":1431},{},[1432],{"type":28,"value":1433},"        'age': '19',\n",{"type":18,"tag":239,"props":1435,"children":1436},{"class":241,"line":1269},[1437],{"type":18,"tag":239,"props":1438,"children":1439},{},[1440],{"type":28,"value":1441},"        'sex': 'girl'},\n",{"type":18,"tag":239,"props":1443,"children":1445},{"class":241,"line":1444},9,[1446],{"type":18,"tag":239,"props":1447,"children":1448},{},[1449],{"type":28,"value":1450}," '王五': {'address': 'HeNan',\n",{"type":18,"tag":239,"props":1452,"children":1454},{"class":241,"line":1453},10,[1455],{"type":18,"tag":239,"props":1456,"children":1457},{},[1458],{"type":28,"value":1459},"        'age': '20',\n",{"type":18,"tag":239,"props":1461,"children":1463},{"class":241,"line":1462},11,[1464],{"type":18,"tag":239,"props":1465,"children":1466},{},[1467],{"type":28,"value":1468},"        'sex': 'boy'}}\n",{"type":18,"tag":239,"props":1470,"children":1472},{"class":241,"line":1471},12,[1473],{"type":18,"tag":239,"props":1474,"children":1475},{},[1476],{"type":28,"value":1303},{"type":18,"tag":23,"props":1478,"children":1480},{"id":1479},"进阶版输出",[1481],{"type":28,"value":1479},{"type":18,"tag":1483,"props":1484,"children":1486},"h4",{"id":1485},"参数介绍",[1487],{"type":28,"value":1485},{"type":18,"tag":31,"props":1489,"children":1490},{},[1491,1496],{"type":18,"tag":235,"props":1492,"children":1494},{"className":1493},[],[1495],{"type":28,"value":1052},{"type":28,"value":1497},"函数的语法格式如下：",{"type":18,"tag":228,"props":1499,"children":1501},{"code":1500,"language":231,"meta":7,"className":232,"style":7},"print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n",[1502],{"type":18,"tag":235,"props":1503,"children":1504},{"__ignoreMap":7},[1505],{"type":18,"tag":239,"props":1506,"children":1507},{"class":241,"line":242},[1508],{"type":18,"tag":239,"props":1509,"children":1510},{},[1511],{"type":28,"value":1500},{"type":18,"tag":31,"props":1513,"children":1514},{},[1515],{"type":18,"tag":35,"props":1516,"children":1517},{},[1518],{"type":28,"value":1519},"参数说明：",{"type":18,"tag":148,"props":1521,"children":1522},{},[1523,1534,1545,1556,1591,1618],{"type":18,"tag":152,"props":1524,"children":1525},{},[1526,1532],{"type":18,"tag":235,"props":1527,"children":1529},{"className":1528},[],[1530],{"type":28,"value":1531},"value",{"type":28,"value":1533},"：表示要输出的值；可以是数字、字符串、各种类型的变量等；",{"type":18,"tag":152,"props":1535,"children":1536},{},[1537,1543],{"type":18,"tag":235,"props":1538,"children":1540},{"className":1539},[],[1541],{"type":28,"value":1542},"…",{"type":28,"value":1544},"：值列表，表示可以一次性打印多个值；输出多个值时，需要使用“,”（英文半角的逗号）分隔，打印出来各个值之间默认用空格隔开；",{"type":18,"tag":152,"props":1546,"children":1547},{},[1548,1554],{"type":18,"tag":235,"props":1549,"children":1551},{"className":1550},[],[1552],{"type":28,"value":1553},"sep",{"type":28,"value":1555},"：表示打印值时，各个值之间的间隔符，默认值是一个空格，可以设置为其他的分隔符；",{"type":18,"tag":152,"props":1557,"children":1558},{},[1559,1565,1567,1573,1575,1581,1583,1589],{"type":18,"tag":235,"props":1560,"children":1562},{"className":1561},[],[1563],{"type":28,"value":1564},"end",{"type":28,"value":1566},"：表示打印完最后一个值需要添加的字符串，用来设定输出语句以什么结尾，默认是换行符",{"type":18,"tag":235,"props":1568,"children":1570},{"className":1569},[],[1571],{"type":28,"value":1572},"\\n",{"type":28,"value":1574},"，即打印完会跳到新行，可以换成其他字符串，如",{"type":18,"tag":235,"props":1576,"children":1578},{"className":1577},[],[1579],{"type":28,"value":1580},"end='\\t'",{"type":28,"value":1582}," 或",{"type":18,"tag":235,"props":1584,"children":1586},{"className":1585},[],[1587],{"type":28,"value":1588},"end=' '",{"type":28,"value":1590},"等，以实现不换行输出；",{"type":18,"tag":152,"props":1592,"children":1593},{},[1594,1600,1602,1608,1610,1616],{"type":18,"tag":235,"props":1595,"children":1597},{"className":1596},[],[1598],{"type":28,"value":1599},"file",{"type":28,"value":1601},"：表示输出的目标对象，可以是文件也可以是数据流，默认是",{"type":18,"tag":235,"props":1603,"children":1605},{"className":1604},[],[1606],{"type":28,"value":1607},"sys.stdout",{"type":28,"value":1609},"。可以设置“",{"type":18,"tag":235,"props":1611,"children":1613},{"className":1612},[],[1614],{"type":28,"value":1615},"file = 文件储存对象",{"type":28,"value":1617},"”，把内容存到该文件中；",{"type":18,"tag":152,"props":1619,"children":1620},{},[1621,1627,1629,1635,1637,1643],{"type":18,"tag":235,"props":1622,"children":1624},{"className":1623},[],[1625],{"type":28,"value":1626},"flush",{"type":28,"value":1628},"：表示是否立刻将输出语句输出到目标对象，flush值为False或者True，默认",{"type":18,"tag":235,"props":1630,"children":1632},{"className":1631},[],[1633],{"type":28,"value":1634},"flush=False",{"type":28,"value":1636},"，表示输出值会保存在缓存中；当",{"type":18,"tag":235,"props":1638,"children":1640},{"className":1639},[],[1641],{"type":28,"value":1642},"flush=True",{"type":28,"value":1644},"时，输出值强制写入文件。",{"type":18,"tag":68,"props":1646,"children":1647},{},[1648],{"type":18,"tag":31,"props":1649,"children":1650},{},[1651,1653,1658,1659,1664,1666,1671,1673,1679,1681,1686,1688,1693,1694,1699,1701,1706,1707,1712,1713,1718,1720,1725,1727,1732,1734,1739,1741,1746],{"type":28,"value":1652},"提示：",{"type":18,"tag":235,"props":1654,"children":1656},{"className":1655},[],[1657],{"type":28,"value":1553},{"type":28,"value":100},{"type":18,"tag":235,"props":1660,"children":1662},{"className":1661},[],[1663],{"type":28,"value":1564},{"type":28,"value":1665},"的参数",{"type":18,"tag":35,"props":1667,"children":1668},{},[1669],{"type":28,"value":1670},"必须是字符串",{"type":28,"value":1672},"；或者为",{"type":18,"tag":235,"props":1674,"children":1676},{"className":1675},[],[1677],{"type":28,"value":1678},"None",{"type":28,"value":1680},"，为",{"type":18,"tag":235,"props":1682,"children":1684},{"className":1683},[],[1685],{"type":28,"value":1678},{"type":28,"value":1687},"时意味着",{"type":18,"tag":35,"props":1689,"children":1690},{},[1691],{"type":28,"value":1692},"使用其默认值",{"type":28,"value":370},{"type":18,"tag":235,"props":1695,"children":1697},{"className":1696},[],[1698],{"type":28,"value":1553},{"type":28,"value":1700},"、",{"type":18,"tag":235,"props":1702,"children":1704},{"className":1703},[],[1705],{"type":28,"value":1564},{"type":28,"value":1700},{"type":18,"tag":235,"props":1708,"children":1710},{"className":1709},[],[1711],{"type":28,"value":1599},{"type":28,"value":1700},{"type":18,"tag":235,"props":1714,"children":1716},{"className":1715},[],[1717],{"type":28,"value":1626},{"type":28,"value":1719},"都",{"type":18,"tag":35,"props":1721,"children":1722},{},[1723],{"type":28,"value":1724},"必须以命名参数方式传参，否则会被当作需要输出的对象",{"type":28,"value":1726},"。如果",{"type":18,"tag":235,"props":1728,"children":1730},{"className":1729},[],[1731],{"type":28,"value":1052},{"type":28,"value":1733},"函数不传递任何参数，将会输出",{"type":18,"tag":235,"props":1735,"children":1737},{"className":1736},[],[1738],{"type":28,"value":1564},{"type":28,"value":1740},"参数的默认值，即",{"type":18,"tag":35,"props":1742,"children":1743},{},[1744],{"type":28,"value":1745},"打印一个空行",{"type":28,"value":370},{"type":18,"tag":1483,"props":1748,"children":1750},{"id":1749},"锦囊01输出字符串",[1751],{"type":28,"value":1752},"锦囊01  输出字符串",{"type":18,"tag":31,"props":1754,"children":1755},{},[1756],{"type":28,"value":1757},"字符串可以直接输出，也可以和数字、运算符等形成表达式进行输出。示例代码如下：",{"type":18,"tag":228,"props":1759,"children":1761},{"code":1760,"language":231,"meta":7,"className":232,"style":7},"print()                         # 输出一个空行  \nprint('')                       # 输出一个空行  \n# 使用三引号可多行输出字符，如三行输出的服务器登录界面  \nprint('''      登录服务器  \n管理员：___________  \n密  码：___________    '''  )   # 字符最前和最后用三引号\n",[1762],{"type":18,"tag":235,"props":1763,"children":1764},{"__ignoreMap":7},[1765,1773,1781,1789,1797,1805],{"type":18,"tag":239,"props":1766,"children":1767},{"class":241,"line":242},[1768],{"type":18,"tag":239,"props":1769,"children":1770},{},[1771],{"type":28,"value":1772},"print()                         # 输出一个空行  \n",{"type":18,"tag":239,"props":1774,"children":1775},{"class":241,"line":251},[1776],{"type":18,"tag":239,"props":1777,"children":1778},{},[1779],{"type":28,"value":1780},"print('')                       # 输出一个空行  \n",{"type":18,"tag":239,"props":1782,"children":1783},{"class":241,"line":396},[1784],{"type":18,"tag":239,"props":1785,"children":1786},{},[1787],{"type":28,"value":1788},"# 使用三引号可多行输出字符，如三行输出的服务器登录界面  \n",{"type":18,"tag":239,"props":1790,"children":1791},{"class":241,"line":405},[1792],{"type":18,"tag":239,"props":1793,"children":1794},{},[1795],{"type":28,"value":1796},"print('''      登录服务器  \n",{"type":18,"tag":239,"props":1798,"children":1799},{"class":241,"line":415},[1800],{"type":18,"tag":239,"props":1801,"children":1802},{},[1803],{"type":28,"value":1804},"管理员：___________  \n",{"type":18,"tag":239,"props":1806,"children":1807},{"class":241,"line":424},[1808],{"type":18,"tag":239,"props":1809,"children":1810},{},[1811],{"type":28,"value":1812},"密  码：___________    '''  )   # 字符最前和最后用三引号\n",{"type":18,"tag":31,"props":1814,"children":1815},{},[1816],{"type":28,"value":1817},"运行结果如下：",{"type":18,"tag":228,"props":1819,"children":1821},{"code":1820,"language":231,"meta":7,"className":232,"style":7},"\n\n      登录服务器\n管理员：___________\n密  码：___________ \n",[1822],{"type":18,"tag":235,"props":1823,"children":1824},{"__ignoreMap":7},[1825,1832,1839,1847,1855],{"type":18,"tag":239,"props":1826,"children":1827},{"class":241,"line":242},[1828],{"type":18,"tag":239,"props":1829,"children":1830},{"emptyLinePlaceholder":409},[1831],{"type":28,"value":412},{"type":18,"tag":239,"props":1833,"children":1834},{"class":241,"line":251},[1835],{"type":18,"tag":239,"props":1836,"children":1837},{"emptyLinePlaceholder":409},[1838],{"type":28,"value":412},{"type":18,"tag":239,"props":1840,"children":1841},{"class":241,"line":396},[1842],{"type":18,"tag":239,"props":1843,"children":1844},{},[1845],{"type":28,"value":1846},"      登录服务器\n",{"type":18,"tag":239,"props":1848,"children":1849},{"class":241,"line":405},[1850],{"type":18,"tag":239,"props":1851,"children":1852},{},[1853],{"type":28,"value":1854},"管理员：___________\n",{"type":18,"tag":239,"props":1856,"children":1857},{"class":241,"line":415},[1858],{"type":18,"tag":239,"props":1859,"children":1860},{},[1861],{"type":28,"value":1862},"密  码：___________\n",{"type":18,"tag":228,"props":1864,"children":1866},{"code":1865,"language":231,"meta":7,"className":232,"style":7},"print(\"没有伟大的愿望，就没有伟大的天才!\")   # 使用双引号将字符串括起来\n",[1867],{"type":18,"tag":235,"props":1868,"children":1869},{"__ignoreMap":7},[1870],{"type":18,"tag":239,"props":1871,"children":1872},{"class":241,"line":242},[1873],{"type":18,"tag":239,"props":1874,"children":1875},{},[1876],{"type":28,"value":1865},{"type":18,"tag":31,"props":1878,"children":1879},{},[1880],{"type":28,"value":1817},{"type":18,"tag":228,"props":1882,"children":1884},{"code":1883},"没有伟大的愿望，就没有伟大的天才!\n",[1885],{"type":18,"tag":235,"props":1886,"children":1887},{"__ignoreMap":7},[1888],{"type":28,"value":1883},{"type":18,"tag":228,"props":1890,"children":1892},{"code":1891,"language":231,"meta":7,"className":232,"style":7},"print('go big or go home')                   # 使用单引号将字符串括起来\n",[1893],{"type":18,"tag":235,"props":1894,"children":1895},{"__ignoreMap":7},[1896],{"type":18,"tag":239,"props":1897,"children":1898},{"class":241,"line":242},[1899],{"type":18,"tag":239,"props":1900,"children":1901},{},[1902],{"type":28,"value":1891},{"type":18,"tag":31,"props":1904,"children":1905},{},[1906],{"type":28,"value":1817},{"type":18,"tag":228,"props":1908,"children":1910},{"code":1909},"go big or go home\n",[1911],{"type":18,"tag":235,"props":1912,"children":1913},{"__ignoreMap":7},[1914],{"type":28,"value":1909},{"type":18,"tag":228,"props":1916,"children":1918},{"code":1917,"language":231,"meta":7,"className":232,"style":7},"print('go','big','or','go','home')         # 字符之间用','间隔，则字符串用空格连接\n",[1919],{"type":18,"tag":235,"props":1920,"children":1921},{"__ignoreMap":7},[1922],{"type":18,"tag":239,"props":1923,"children":1924},{"class":241,"line":242},[1925],{"type":18,"tag":239,"props":1926,"children":1927},{},[1928],{"type":28,"value":1917},{"type":18,"tag":31,"props":1930,"children":1931},{},[1932],{"type":28,"value":1817},{"type":18,"tag":228,"props":1934,"children":1935},{"code":1909},[1936],{"type":18,"tag":235,"props":1937,"children":1938},{"__ignoreMap":7},[1939],{"type":28,"value":1909},{"type":18,"tag":228,"props":1941,"children":1943},{"code":1942,"language":231,"meta":7,"className":232,"style":7},"print('go' 'big' 'or' 'go' 'home')         # 字符之间不用','间隔，则字符串无空格连接\n",[1944],{"type":18,"tag":235,"props":1945,"children":1946},{"__ignoreMap":7},[1947],{"type":18,"tag":239,"props":1948,"children":1949},{"class":241,"line":242},[1950],{"type":18,"tag":239,"props":1951,"children":1952},{},[1953],{"type":28,"value":1942},{"type":18,"tag":31,"props":1955,"children":1956},{},[1957],{"type":28,"value":1817},{"type":18,"tag":228,"props":1959,"children":1961},{"code":1960},"Gobigorgohome\n",[1962],{"type":18,"tag":235,"props":1963,"children":1964},{"__ignoreMap":7},[1965],{"type":28,"value":1960},{"type":18,"tag":228,"props":1967,"children":1969},{"code":1968,"language":231,"meta":7,"className":232,"style":7},"print('go'+ 'big'+ 'or'+'go'+'home')   # 用加号“+” 连接输出字符串\n",[1970],{"type":18,"tag":235,"props":1971,"children":1972},{"__ignoreMap":7},[1973],{"type":18,"tag":239,"props":1974,"children":1975},{"class":241,"line":242},[1976],{"type":18,"tag":239,"props":1977,"children":1978},{},[1979],{"type":28,"value":1968},{"type":18,"tag":31,"props":1981,"children":1982},{},[1983],{"type":28,"value":1817},{"type":18,"tag":228,"props":1985,"children":1986},{"code":1960},[1987],{"type":18,"tag":235,"props":1988,"children":1989},{"__ignoreMap":7},[1990],{"type":28,"value":1960},{"type":18,"tag":228,"props":1992,"children":1994},{"code":1993,"language":231,"meta":7,"className":232,"style":7},"print('www','mingrisoft','com',sep='.')    # 设置间隔符,字符之间用'.'间隔\n",[1995],{"type":18,"tag":235,"props":1996,"children":1997},{"__ignoreMap":7},[1998],{"type":18,"tag":239,"props":1999,"children":2000},{"class":241,"line":242},[2001],{"type":18,"tag":239,"props":2002,"children":2003},{},[2004],{"type":28,"value":1993},{"type":18,"tag":31,"props":2006,"children":2007},{},[2008],{"type":28,"value":1817},{"type":18,"tag":228,"props":2010,"children":2012},{"code":2011},"www.mingrisoft.com\n",[2013],{"type":18,"tag":235,"props":2014,"children":2015},{"__ignoreMap":7},[2016],{"type":28,"value":2011},{"type":18,"tag":228,"props":2018,"children":2020},{"code":2019,"language":231,"meta":7,"className":232,"style":7},"print('2020','7','24',sep='-')              # 设置间隔符,字符之间用'-'间隔\n",[2021],{"type":18,"tag":235,"props":2022,"children":2023},{"__ignoreMap":7},[2024],{"type":18,"tag":239,"props":2025,"children":2026},{"class":241,"line":242},[2027],{"type":18,"tag":239,"props":2028,"children":2029},{},[2030],{"type":28,"value":2019},{"type":18,"tag":31,"props":2032,"children":2033},{},[2034],{"type":28,"value":1817},{"type":18,"tag":228,"props":2036,"children":2038},{"code":2037},"2020-7-24\n",[2039],{"type":18,"tag":235,"props":2040,"children":2041},{"__ignoreMap":7},[2042],{"type":28,"value":2037},{"type":18,"tag":228,"props":2044,"children":2046},{"code":2045,"language":231,"meta":7,"className":232,"style":7},"print(50 * '= ')            # 一次输出多个字符，使用数字、运算符和字符串\n",[2047],{"type":18,"tag":235,"props":2048,"children":2049},{"__ignoreMap":7},[2050],{"type":18,"tag":239,"props":2051,"children":2052},{"class":241,"line":242},[2053],{"type":18,"tag":239,"props":2054,"children":2055},{},[2056],{"type":28,"value":2045},{"type":18,"tag":31,"props":2058,"children":2059},{},[2060],{"type":28,"value":1817},{"type":18,"tag":228,"props":2062,"children":2064},{"code":2063},"===================================================================\n",[2065],{"type":18,"tag":235,"props":2066,"children":2067},{"__ignoreMap":7},[2068],{"type":28,"value":2063},{"type":18,"tag":228,"props":2070,"children":2072},{"code":2071,"language":231,"meta":7,"className":232,"style":7},"# 使用chr()函数，根据字符的ASCII值，输出字符  \nprint(chr(65))              # 大写字母的ASCII值为65~90\n",[2073],{"type":18,"tag":235,"props":2074,"children":2075},{"__ignoreMap":7},[2076,2084],{"type":18,"tag":239,"props":2077,"children":2078},{"class":241,"line":242},[2079],{"type":18,"tag":239,"props":2080,"children":2081},{},[2082],{"type":28,"value":2083},"# 使用chr()函数，根据字符的ASCII值，输出字符  \n",{"type":18,"tag":239,"props":2085,"children":2086},{"class":241,"line":251},[2087],{"type":18,"tag":239,"props":2088,"children":2089},{},[2090],{"type":28,"value":2091},"print(chr(65))              # 大写字母的ASCII值为65~90\n",{"type":18,"tag":31,"props":2093,"children":2094},{},[2095],{"type":28,"value":1817},{"type":18,"tag":228,"props":2097,"children":2099},{"code":2098},"A\n",[2100],{"type":18,"tag":235,"props":2101,"children":2102},{"__ignoreMap":7},[2103],{"type":28,"value":2098},{"type":18,"tag":228,"props":2105,"children":2107},{"code":2106,"language":231,"meta":7,"className":232,"style":7},"print(chr(97))              # 小写字母的ASCII值为97~122\n",[2108],{"type":18,"tag":235,"props":2109,"children":2110},{"__ignoreMap":7},[2111],{"type":18,"tag":239,"props":2112,"children":2113},{"class":241,"line":242},[2114],{"type":18,"tag":239,"props":2115,"children":2116},{},[2117],{"type":28,"value":2106},{"type":18,"tag":31,"props":2119,"children":2120},{},[2121],{"type":28,"value":1817},{"type":18,"tag":228,"props":2123,"children":2125},{"code":2124},"a\n",[2126],{"type":18,"tag":235,"props":2127,"children":2128},{"__ignoreMap":7},[2129],{"type":28,"value":2124},{"type":18,"tag":228,"props":2131,"children":2133},{"code":2132,"language":231,"meta":7,"className":232,"style":7},"print(chr(8544),chr(8545),chr(8546),chr(8547))\n",[2134],{"type":18,"tag":235,"props":2135,"children":2136},{"__ignoreMap":7},[2137],{"type":18,"tag":239,"props":2138,"children":2139},{"class":241,"line":242},[2140],{"type":18,"tag":239,"props":2141,"children":2142},{},[2143],{"type":28,"value":2132},{"type":18,"tag":31,"props":2145,"children":2146},{},[2147],{"type":28,"value":1817},{"type":18,"tag":228,"props":2149,"children":2151},{"code":2150},"Ⅰ Ⅱ Ⅲ Ⅳ\n",[2152],{"type":18,"tag":235,"props":2153,"children":2154},{"__ignoreMap":7},[2155],{"type":28,"value":2150},{"type":18,"tag":228,"props":2157,"children":2159},{"code":2158,"language":231,"meta":7,"className":232,"style":7},"# 使用ord()函数将字符转换为对应的整数  \nprint(ord('生'),ord('化'),ord('危'),ord('机'))\n",[2160],{"type":18,"tag":235,"props":2161,"children":2162},{"__ignoreMap":7},[2163,2171],{"type":18,"tag":239,"props":2164,"children":2165},{"class":241,"line":242},[2166],{"type":18,"tag":239,"props":2167,"children":2168},{},[2169],{"type":28,"value":2170},"# 使用ord()函数将字符转换为对应的整数  \n",{"type":18,"tag":239,"props":2172,"children":2173},{"class":241,"line":251},[2174],{"type":18,"tag":239,"props":2175,"children":2176},{},[2177],{"type":28,"value":2178},"print(ord('生'),ord('化'),ord('危'),ord('机'))\n",{"type":18,"tag":31,"props":2180,"children":2181},{},[2182],{"type":28,"value":1817},{"type":18,"tag":228,"props":2184,"children":2186},{"code":2185},"29983 21270 21361 26426\n",[2187],{"type":18,"tag":235,"props":2188,"children":2189},{"__ignoreMap":7},[2190],{"type":28,"value":2185},{"type":18,"tag":1483,"props":2192,"children":2194},{"id":2193},"锦囊02输出数值",[2195],{"type":28,"value":2196},"锦囊02  输出数值",{"type":18,"tag":31,"props":2198,"children":2199},{},[2200],{"type":28,"value":2201},"数值类型可以直接输出，但使用“+”连接数值和其他数据类型时，系统会默认为是加法计算，会报错。可以使用“,”连接，或者将数值作为字符串来处理，两端加单引号或双引号。示例代码如下：",{"type":18,"tag":228,"props":2203,"children":2205},{"code":2204,"language":231,"meta":7,"className":232,"style":7},"print(1314)                       # 直接输出整数，可不带双引号或单引号。输出结果：1314  \nprint(12.22)                      # 直接输出浮点数。输出结果：12.22  \nprint(10 \u002F 3)                     # 可以包含算术表达式，输出运算结果为：3.3333333333333335  \nprint(100 * 3.13 + 60)           # 可以包含算术表达式，输出运算结果为：373  \nprint(2, 0, 2, 0)                 # 使用“,”连接要输出的数值，中间用空格连接。输出结果：2 0 2 0  \nprint(192, 168, 1, 1, sep='.')   # 使用“.”连接输出数值，数值间用“.”间隔。输出结果：192.168.1.1  \nprint(\"广州恒大\" + 43)             # 不能直接使用“+”连接字符串和数值，会报错。异常信息为：TypeError: can only concatenate str (not \"int\") to str  \nprint(\"广州恒大\" + str(43)) # 使用“+”连接字符串和数值时，数值要转换为字符串。输出结果：广州恒大43  \nprint(\"广州恒大\", 43)      # 使用“,”连接字符串和数值，字符串和数值用空格分隔。输出结果：广州恒大 43\nprint(\"%e\" % 120563332111098)     # 使用操作符\"%e\"%格式化数值为科学记数法。输出结果：1.205633e+14\n",[2206],{"type":18,"tag":235,"props":2207,"children":2208},{"__ignoreMap":7},[2209,2217,2225,2233,2241,2249,2257,2265,2273,2281],{"type":18,"tag":239,"props":2210,"children":2211},{"class":241,"line":242},[2212],{"type":18,"tag":239,"props":2213,"children":2214},{},[2215],{"type":28,"value":2216},"print(1314)                       # 直接输出整数，可不带双引号或单引号。输出结果：1314  \n",{"type":18,"tag":239,"props":2218,"children":2219},{"class":241,"line":251},[2220],{"type":18,"tag":239,"props":2221,"children":2222},{},[2223],{"type":28,"value":2224},"print(12.22)                      # 直接输出浮点数。输出结果：12.22  \n",{"type":18,"tag":239,"props":2226,"children":2227},{"class":241,"line":396},[2228],{"type":18,"tag":239,"props":2229,"children":2230},{},[2231],{"type":28,"value":2232},"print(10 \u002F 3)                     # 可以包含算术表达式，输出运算结果为：3.3333333333333335  \n",{"type":18,"tag":239,"props":2234,"children":2235},{"class":241,"line":405},[2236],{"type":18,"tag":239,"props":2237,"children":2238},{},[2239],{"type":28,"value":2240},"print(100 * 3.13 + 60)           # 可以包含算术表达式，输出运算结果为：373  \n",{"type":18,"tag":239,"props":2242,"children":2243},{"class":241,"line":415},[2244],{"type":18,"tag":239,"props":2245,"children":2246},{},[2247],{"type":28,"value":2248},"print(2, 0, 2, 0)                 # 使用“,”连接要输出的数值，中间用空格连接。输出结果：2 0 2 0  \n",{"type":18,"tag":239,"props":2250,"children":2251},{"class":241,"line":424},[2252],{"type":18,"tag":239,"props":2253,"children":2254},{},[2255],{"type":28,"value":2256},"print(192, 168, 1, 1, sep='.')   # 使用“.”连接输出数值，数值间用“.”间隔。输出结果：192.168.1.1  \n",{"type":18,"tag":239,"props":2258,"children":2259},{"class":241,"line":732},[2260],{"type":18,"tag":239,"props":2261,"children":2262},{},[2263],{"type":28,"value":2264},"print(\"广州恒大\" + 43)             # 不能直接使用“+”连接字符串和数值，会报错。异常信息为：TypeError: can only concatenate str (not \"int\") to str  \n",{"type":18,"tag":239,"props":2266,"children":2267},{"class":241,"line":1269},[2268],{"type":18,"tag":239,"props":2269,"children":2270},{},[2271],{"type":28,"value":2272},"print(\"广州恒大\" + str(43)) # 使用“+”连接字符串和数值时，数值要转换为字符串。输出结果：广州恒大43  \n",{"type":18,"tag":239,"props":2274,"children":2275},{"class":241,"line":1444},[2276],{"type":18,"tag":239,"props":2277,"children":2278},{},[2279],{"type":28,"value":2280},"print(\"广州恒大\", 43)      # 使用“,”连接字符串和数值，字符串和数值用空格分隔。输出结果：广州恒大 43\n",{"type":18,"tag":239,"props":2282,"children":2283},{"class":241,"line":1453},[2284],{"type":18,"tag":239,"props":2285,"children":2286},{},[2287],{"type":28,"value":2288},"print(\"%e\" % 120563332111098)     # 使用操作符\"%e\"%格式化数值为科学记数法。输出结果：1.205633e+14\n",{"type":18,"tag":1483,"props":2290,"children":2292},{"id":2291},"锦囊03-输出变量",[2293],{"type":28,"value":2294},"锦囊03  输出变量",{"type":18,"tag":31,"props":2296,"children":2297},{},[2298],{"type":28,"value":2299},"字符串、数值型、布尔型、列表、字典等各种变量都可以直接输出。示例代码如下：",{"type":18,"tag":228,"props":2301,"children":2303},{"code":2302,"language":231,"meta":7,"className":232,"style":7},"stra= 'go big or go home'      # 定义一个字符串变量stra  \nprint(stra)                    # 输出变量stra的值\n",[2304],{"type":18,"tag":235,"props":2305,"children":2306},{"__ignoreMap":7},[2307,2315],{"type":18,"tag":239,"props":2308,"children":2309},{"class":241,"line":242},[2310],{"type":18,"tag":239,"props":2311,"children":2312},{},[2313],{"type":28,"value":2314},"stra= 'go big or go home'      # 定义一个字符串变量stra  \n",{"type":18,"tag":239,"props":2316,"children":2317},{"class":241,"line":251},[2318],{"type":18,"tag":239,"props":2319,"children":2320},{},[2321],{"type":28,"value":2322},"print(stra)                    # 输出变量stra的值\n",{"type":18,"tag":31,"props":2324,"children":2325},{},[2326],{"type":28,"value":1817},{"type":18,"tag":228,"props":2328,"children":2329},{"code":1909},[2330],{"type":18,"tag":235,"props":2331,"children":2332},{"__ignoreMap":7},[2333],{"type":28,"value":1909},{"type":18,"tag":228,"props":2335,"children":2337},{"code":2336,"language":231,"meta":7,"className":232,"style":7},"num = 27                       # 定义一个数值型变量num  \nprint(num)                     # 输出变量num的值\n",[2338],{"type":18,"tag":235,"props":2339,"children":2340},{"__ignoreMap":7},[2341,2349],{"type":18,"tag":239,"props":2342,"children":2343},{"class":241,"line":242},[2344],{"type":18,"tag":239,"props":2345,"children":2346},{},[2347],{"type":28,"value":2348},"num = 27                       # 定义一个数值型变量num  \n",{"type":18,"tag":239,"props":2350,"children":2351},{"class":241,"line":251},[2352],{"type":18,"tag":239,"props":2353,"children":2354},{},[2355],{"type":28,"value":2356},"print(num)                     # 输出变量num的值\n",{"type":18,"tag":31,"props":2358,"children":2359},{},[2360],{"type":28,"value":1817},{"type":18,"tag":228,"props":2362,"children":2364},{"code":2363},"27\n",[2365],{"type":18,"tag":235,"props":2366,"children":2367},{"__ignoreMap":7},[2368],{"type":28,"value":2363},{"type":18,"tag":228,"props":2370,"children":2372},{"code":2371,"language":231,"meta":7,"className":232,"style":7},"stra= '你若盛开'               # 定义字符串变量stra  \nstrb= '蝴蝶自来'               # 定义字符串变量strb  \nprint(stra,strb)              # 使用“，”连接变量stra和strb，中间用空格分隔  \nprint(stra +'\\n' + strb)      # 使用'\\n'连接变量stra和strb，换行分隔  \nprint(stra + strb)            # 使用“+”连接变量stra和strb，直接连接无空格\n",[2373],{"type":18,"tag":235,"props":2374,"children":2375},{"__ignoreMap":7},[2376,2384,2392,2400,2408],{"type":18,"tag":239,"props":2377,"children":2378},{"class":241,"line":242},[2379],{"type":18,"tag":239,"props":2380,"children":2381},{},[2382],{"type":28,"value":2383},"stra= '你若盛开'               # 定义字符串变量stra  \n",{"type":18,"tag":239,"props":2385,"children":2386},{"class":241,"line":251},[2387],{"type":18,"tag":239,"props":2388,"children":2389},{},[2390],{"type":28,"value":2391},"strb= '蝴蝶自来'               # 定义字符串变量strb  \n",{"type":18,"tag":239,"props":2393,"children":2394},{"class":241,"line":396},[2395],{"type":18,"tag":239,"props":2396,"children":2397},{},[2398],{"type":28,"value":2399},"print(stra,strb)              # 使用“，”连接变量stra和strb，中间用空格分隔  \n",{"type":18,"tag":239,"props":2401,"children":2402},{"class":241,"line":405},[2403],{"type":18,"tag":239,"props":2404,"children":2405},{},[2406],{"type":28,"value":2407},"print(stra +'\\n' + strb)      # 使用'\\n'连接变量stra和strb，换行分隔  \n",{"type":18,"tag":239,"props":2409,"children":2410},{"class":241,"line":415},[2411],{"type":18,"tag":239,"props":2412,"children":2413},{},[2414],{"type":28,"value":2415},"print(stra + strb)            # 使用“+”连接变量stra和strb，直接连接无空格\n",{"type":18,"tag":31,"props":2417,"children":2418},{},[2419],{"type":28,"value":1817},{"type":18,"tag":228,"props":2421,"children":2423},{"code":2422},"你若盛开 蝴蝶自来\n你若盛开\n蝴蝶自来\n你若盛开蝴蝶自来\n",[2424],{"type":18,"tag":235,"props":2425,"children":2426},{"__ignoreMap":7},[2427],{"type":28,"value":2422},{"type":18,"tag":228,"props":2429,"children":2431},{"code":2430,"language":231,"meta":7,"className":232,"style":7},"print(stra +'\\n' , strb)     # 添加'\\n'换行后，使用“，”连接的字符串前面仍然有一个空格\n",[2432],{"type":18,"tag":235,"props":2433,"children":2434},{"__ignoreMap":7},[2435],{"type":18,"tag":239,"props":2436,"children":2437},{"class":241,"line":242},[2438],{"type":18,"tag":239,"props":2439,"children":2440},{},[2441],{"type":28,"value":2430},{"type":18,"tag":31,"props":2443,"children":2444},{},[2445],{"type":28,"value":1817},{"type":18,"tag":228,"props":2447,"children":2449},{"code":2448},"你若盛开\n 蝴蝶自来\n",[2450],{"type":18,"tag":235,"props":2451,"children":2452},{"__ignoreMap":7},[2453],{"type":28,"value":2448},{"type":18,"tag":228,"props":2455,"children":2457},{"code":2456,"language":231,"meta":7,"className":232,"style":7},"name = ['杨过','临安','1224','小龙女']  \n  \nprint(name)  \nprint('--'.join(name))                 # 使用“--”连接列表内数据  \nprint(' '.join(name))                  # 使用空格“ ”连接列表内数据  \nprint(''.join(name))                   # 直接连接列表内数据\n",[2458],{"type":18,"tag":235,"props":2459,"children":2460},{"__ignoreMap":7},[2461,2469,2477,2485,2493,2501],{"type":18,"tag":239,"props":2462,"children":2463},{"class":241,"line":242},[2464],{"type":18,"tag":239,"props":2465,"children":2466},{},[2467],{"type":28,"value":2468},"name = ['杨过','临安','1224','小龙女']  \n",{"type":18,"tag":239,"props":2470,"children":2471},{"class":241,"line":251},[2472],{"type":18,"tag":239,"props":2473,"children":2474},{},[2475],{"type":28,"value":2476},"  \n",{"type":18,"tag":239,"props":2478,"children":2479},{"class":241,"line":396},[2480],{"type":18,"tag":239,"props":2481,"children":2482},{},[2483],{"type":28,"value":2484},"print(name)  \n",{"type":18,"tag":239,"props":2486,"children":2487},{"class":241,"line":405},[2488],{"type":18,"tag":239,"props":2489,"children":2490},{},[2491],{"type":28,"value":2492},"print('--'.join(name))                 # 使用“--”连接列表内数据  \n",{"type":18,"tag":239,"props":2494,"children":2495},{"class":241,"line":415},[2496],{"type":18,"tag":239,"props":2497,"children":2498},{},[2499],{"type":28,"value":2500},"print(' '.join(name))                  # 使用空格“ ”连接列表内数据  \n",{"type":18,"tag":239,"props":2502,"children":2503},{"class":241,"line":424},[2504],{"type":18,"tag":239,"props":2505,"children":2506},{},[2507],{"type":28,"value":2508},"print(''.join(name))                   # 直接连接列表内数据\n",{"type":18,"tag":31,"props":2510,"children":2511},{},[2512],{"type":28,"value":1817},{"type":18,"tag":228,"props":2514,"children":2516},{"code":2515},"['杨过', '临安', '1224', '小龙女']\n杨过--临安--1224--小龙女\n杨过 临安 1224 小龙女\n杨过临安1224小龙女\n",[2517],{"type":18,"tag":235,"props":2518,"children":2519},{"__ignoreMap":7},[2520],{"type":28,"value":2515},{"type":18,"tag":228,"props":2522,"children":2524},{"code":2523,"language":231,"meta":7,"className":232,"style":7},"word = '世界那么大，'  \nname= '黄蓉'  \nhow= '想出去看看！！'  \nprint(word, name, how)                   # 用“，”连接变量，中间用空格分隔  \nprint(word, name, how,sep='.')           # 设置间隔符为“，”  \nprint(word, name, how,sep='****')        # 设置间隔符为“****”\n",[2525],{"type":18,"tag":235,"props":2526,"children":2527},{"__ignoreMap":7},[2528,2536,2544,2552,2560,2568],{"type":18,"tag":239,"props":2529,"children":2530},{"class":241,"line":242},[2531],{"type":18,"tag":239,"props":2532,"children":2533},{},[2534],{"type":28,"value":2535},"word = '世界那么大，'  \n",{"type":18,"tag":239,"props":2537,"children":2538},{"class":241,"line":251},[2539],{"type":18,"tag":239,"props":2540,"children":2541},{},[2542],{"type":28,"value":2543},"name= '黄蓉'  \n",{"type":18,"tag":239,"props":2545,"children":2546},{"class":241,"line":396},[2547],{"type":18,"tag":239,"props":2548,"children":2549},{},[2550],{"type":28,"value":2551},"how= '想出去看看！！'  \n",{"type":18,"tag":239,"props":2553,"children":2554},{"class":241,"line":405},[2555],{"type":18,"tag":239,"props":2556,"children":2557},{},[2558],{"type":28,"value":2559},"print(word, name, how)                   # 用“，”连接变量，中间用空格分隔  \n",{"type":18,"tag":239,"props":2561,"children":2562},{"class":241,"line":415},[2563],{"type":18,"tag":239,"props":2564,"children":2565},{},[2566],{"type":28,"value":2567},"print(word, name, how,sep='.')           # 设置间隔符为“，”  \n",{"type":18,"tag":239,"props":2569,"children":2570},{"class":241,"line":424},[2571],{"type":18,"tag":239,"props":2572,"children":2573},{},[2574],{"type":28,"value":2575},"print(word, name, how,sep='****')        # 设置间隔符为“****”\n",{"type":18,"tag":31,"props":2577,"children":2578},{},[2579],{"type":28,"value":1817},{"type":18,"tag":228,"props":2581,"children":2583},{"code":2582},"世界那么大， 黄蓉 想出去看看！！\n世界那么大，.黄蓉.想出去看看！！\n世界那么大，****黄蓉****想出去看看！！\n",[2584],{"type":18,"tag":235,"props":2585,"children":2586},{"__ignoreMap":7},[2587],{"type":28,"value":2582},{"type":18,"tag":228,"props":2589,"children":2591},{"code":2590,"language":231,"meta":7,"className":232,"style":7},"word = [\"南京\",\"苏州\",\"上海\",\"杭州\",\"宁波\"]  \n  \nfor item in word:                        # 遍历列表  \n    print(item)                           # 输出每个列表元素\n",[2592],{"type":18,"tag":235,"props":2593,"children":2594},{"__ignoreMap":7},[2595,2603,2610,2618],{"type":18,"tag":239,"props":2596,"children":2597},{"class":241,"line":242},[2598],{"type":18,"tag":239,"props":2599,"children":2600},{},[2601],{"type":28,"value":2602},"word = [\"南京\",\"苏州\",\"上海\",\"杭州\",\"宁波\"]  \n",{"type":18,"tag":239,"props":2604,"children":2605},{"class":241,"line":251},[2606],{"type":18,"tag":239,"props":2607,"children":2608},{},[2609],{"type":28,"value":2476},{"type":18,"tag":239,"props":2611,"children":2612},{"class":241,"line":396},[2613],{"type":18,"tag":239,"props":2614,"children":2615},{},[2616],{"type":28,"value":2617},"for item in word:                        # 遍历列表  \n",{"type":18,"tag":239,"props":2619,"children":2620},{"class":241,"line":405},[2621],{"type":18,"tag":239,"props":2622,"children":2623},{},[2624],{"type":28,"value":2625},"    print(item)                           # 输出每个列表元素\n",{"type":18,"tag":31,"props":2627,"children":2628},{},[2629],{"type":28,"value":1817},{"type":18,"tag":228,"props":2631,"children":2633},{"code":2632},"南京\n苏州\n上海\n杭州\n宁波\n",[2634],{"type":18,"tag":235,"props":2635,"children":2636},{"__ignoreMap":7},[2637],{"type":28,"value":2632},{"type":18,"tag":228,"props":2639,"children":2641},{"code":2640,"language":231,"meta":7,"className":232,"style":7},"for item in word:                        # 输出列表变量的数据到一行  \n    print(item + \">>\",end=\"\")            # 元素之间用“>>”连接\n",[2642],{"type":18,"tag":235,"props":2643,"children":2644},{"__ignoreMap":7},[2645,2653],{"type":18,"tag":239,"props":2646,"children":2647},{"class":241,"line":242},[2648],{"type":18,"tag":239,"props":2649,"children":2650},{},[2651],{"type":28,"value":2652},"for item in word:                        # 输出列表变量的数据到一行  \n",{"type":18,"tag":239,"props":2654,"children":2655},{"class":241,"line":251},[2656],{"type":18,"tag":239,"props":2657,"children":2658},{},[2659],{"type":28,"value":2660},"    print(item + \">>\",end=\"\")            # 元素之间用“>>”连接\n",{"type":18,"tag":31,"props":2662,"children":2663},{},[2664],{"type":28,"value":1817},{"type":18,"tag":228,"props":2666,"children":2668},{"code":2667},"南京>>苏州>>上海>>杭州>>宁波>>\n",[2669],{"type":18,"tag":235,"props":2670,"children":2671},{"__ignoreMap":7},[2672],{"type":28,"value":2667},{"type":18,"tag":228,"props":2674,"children":2676},{"code":2675,"language":231,"meta":7,"className":232,"style":7},"team=\"广州恒大\"  \npoints=63  \nprint (team,points)            # 使用“,”可以直接连接字符串变量和数字变量  \n# 使用“+”连接字符串变量和数值变量前，必须先格式化数字变量为字符串  \nprint (team + str(points))\n",[2677],{"type":18,"tag":235,"props":2678,"children":2679},{"__ignoreMap":7},[2680,2688,2696,2704,2712],{"type":18,"tag":239,"props":2681,"children":2682},{"class":241,"line":242},[2683],{"type":18,"tag":239,"props":2684,"children":2685},{},[2686],{"type":28,"value":2687},"team=\"广州恒大\"  \n",{"type":18,"tag":239,"props":2689,"children":2690},{"class":241,"line":251},[2691],{"type":18,"tag":239,"props":2692,"children":2693},{},[2694],{"type":28,"value":2695},"points=63  \n",{"type":18,"tag":239,"props":2697,"children":2698},{"class":241,"line":396},[2699],{"type":18,"tag":239,"props":2700,"children":2701},{},[2702],{"type":28,"value":2703},"print (team,points)            # 使用“,”可以直接连接字符串变量和数字变量  \n",{"type":18,"tag":239,"props":2705,"children":2706},{"class":241,"line":405},[2707],{"type":18,"tag":239,"props":2708,"children":2709},{},[2710],{"type":28,"value":2711},"# 使用“+”连接字符串变量和数值变量前，必须先格式化数字变量为字符串  \n",{"type":18,"tag":239,"props":2713,"children":2714},{"class":241,"line":415},[2715],{"type":18,"tag":239,"props":2716,"children":2717},{},[2718],{"type":28,"value":2719},"print (team + str(points))\n",{"type":18,"tag":31,"props":2721,"children":2722},{},[2723],{"type":28,"value":1817},{"type":18,"tag":228,"props":2725,"children":2727},{"code":2726},"广州恒大 63\n广州恒大63\n",[2728],{"type":18,"tag":235,"props":2729,"children":2730},{"__ignoreMap":7},[2731],{"type":28,"value":2726},{"type":18,"tag":1483,"props":2733,"children":2735},{"id":2734},"锦囊04-特殊文字符号标志输出",[2736],{"type":28,"value":2737},"锦囊04  特殊文字、符号、标志输出",{"type":18,"tag":31,"props":2739,"children":2740},{},[2741,2743,2749],{"type":28,"value":2742},"Windows 10提供的表情包（切换到微软输入法，再通过快捷键",{"type":18,"tag":235,"props":2744,"children":2746},{"className":2745},[],[2747],{"type":28,"value":2748},"Ctrl+Shift+B",{"type":28,"value":2750},"可以调出表情包）提供了大量图标和特殊符号，在PyCharm下可使用大部分表情包，但是在Python自带的IDE中只能使用部分特殊字符。",{"type":18,"tag":31,"props":2752,"children":2753},{},[2754],{"type":28,"value":2755},"在IDLE中，利用Windows 10表情包输入特殊符号，代码如下：",{"type":18,"tag":228,"props":2757,"children":2759},{"code":2758,"language":231,"meta":7,"className":232,"style":7},"print(\"😘😊🤣😍😒\\n💕👌❤️😁👍\")\n",[2760],{"type":18,"tag":235,"props":2761,"children":2762},{"__ignoreMap":7},[2763],{"type":18,"tag":239,"props":2764,"children":2765},{"class":241,"line":242},[2766],{"type":18,"tag":239,"props":2767,"children":2768},{},[2769],{"type":28,"value":2758},{"type":18,"tag":31,"props":2771,"children":2772},{},[2773],{"type":28,"value":2774},"输出结果如下图所示。",{"type":18,"tag":31,"props":2776,"children":2777},{},[2778],{"type":18,"tag":2779,"props":2780,"children":2783},"img",{"alt":2781,"src":2782},"Pasted image 20250812091323","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250812091323.png",[],{"type":18,"tag":68,"props":2785,"children":2786},{},[2787],{"type":18,"tag":31,"props":2788,"children":2789},{},[2790],{"type":28,"value":2791},"调用系统提供的字符映射表，也可以在Pycharm下输出特殊符号和标志。",{"type":18,"tag":31,"props":2793,"children":2794},{},[2795,2797,2803,2805,2811,2813,2818,2820,2824,2826,2832,2834,2840,2841,2847,2849,2855,2857,2863,2865,2871],{"type":28,"value":2796},"按",{"type":18,"tag":235,"props":2798,"children":2800},{"className":2799},[],[2801],{"type":28,"value":2802},"win+R",{"type":28,"value":2804},"键，输入",{"type":18,"tag":235,"props":2806,"children":2808},{"className":2807},[],[2809],{"type":28,"value":2810},"charmap",{"type":28,"value":2812},"，调出字符映射表。单击想要插入到程序中的特殊字符，特殊符号将放大显示。",{"type":18,"tag":35,"props":2814,"children":2815},{},[2816],{"type":28,"value":2817},"记住放大符号旁边的字符码",{"type":28,"value":2819},"。如要输入",{"type":18,"tag":2779,"props":2821,"children":2823},{"alt":7,"src":2822},"http:\u002F\u002Ftest.mingrisoft.com\u002Fuploads\u002Fres_doc\u002FPython\u002F20\u002F101\u002F9944818140306101113.files\u002Fimage008.jpg",[],{"type":28,"value":2825},"，它的字符码为",{"type":18,"tag":235,"props":2827,"children":2829},{"className":2828},[],[2830],{"type":28,"value":2831},"0x43",{"type":28,"value":2833},"，在",{"type":18,"tag":235,"props":2835,"children":2837},{"className":2836},[],[2838],{"type":28,"value":2839},"0x",{"type":28,"value":100},{"type":18,"tag":235,"props":2842,"children":2844},{"className":2843},[],[2845],{"type":28,"value":2846},"43",{"type":28,"value":2848},"之间加入",{"type":18,"tag":235,"props":2850,"children":2852},{"className":2851},[],[2853],{"type":28,"value":2854},"f0",{"type":28,"value":2856},"(零)，即",{"type":18,"tag":235,"props":2858,"children":2860},{"className":2859},[],[2861],{"type":28,"value":2862},"0xf043",{"type":28,"value":2864},"，然后就可以通过",{"type":18,"tag":235,"props":2866,"children":2868},{"className":2867},[],[2869],{"type":28,"value":2870},"chr函数",{"type":28,"value":2872},"进行输出。代码如下：",{"type":18,"tag":228,"props":2874,"children":2876},{"code":2875,"language":231,"meta":7,"className":232,"style":7},"print(chr(0xf043))                      #0xf043是16进制数\n",[2877],{"type":18,"tag":235,"props":2878,"children":2879},{"__ignoreMap":7},[2880],{"type":18,"tag":239,"props":2881,"children":2882},{"class":241,"line":242},[2883],{"type":18,"tag":239,"props":2884,"children":2885},{},[2886],{"type":28,"value":2875},{"type":18,"tag":31,"props":2888,"children":2889},{},[2890,2892],{"type":28,"value":2891},"输出结果为：",{"type":18,"tag":2779,"props":2893,"children":2895},{"alt":7,"src":2894},"http:\u002F\u002Ftest.mingrisoft.com\u002Fuploads\u002Fres_doc\u002FPython\u002F20\u002F101\u002F9944818140306101113.files\u002Fimage009.jpg",[],{"type":18,"tag":228,"props":2897,"children":2899},{"code":2898,"language":231,"meta":7,"className":232,"style":7},"#直接使用字符集的编码，输出多个特殊符号  \nprint(chr(0xf021),chr(0xf035),chr(0xf046),chr(0xf051),chr(0xf067),chr(0xf0e5),chr(0xf0f2))\n",[2900],{"type":18,"tag":235,"props":2901,"children":2902},{"__ignoreMap":7},[2903,2911],{"type":18,"tag":239,"props":2904,"children":2905},{"class":241,"line":242},[2906],{"type":18,"tag":239,"props":2907,"children":2908},{},[2909],{"type":28,"value":2910},"#直接使用字符集的编码，输出多个特殊符号  \n",{"type":18,"tag":239,"props":2912,"children":2913},{"class":241,"line":251},[2914],{"type":18,"tag":239,"props":2915,"children":2916},{},[2917],{"type":28,"value":2918},"print(chr(0xf021),chr(0xf035),chr(0xf046),chr(0xf051),chr(0xf067),chr(0xf0e5),chr(0xf0f2))\n",{"type":18,"tag":31,"props":2920,"children":2921},{},[2922,2923,2927],{"type":28,"value":2891},{"type":18,"tag":2779,"props":2924,"children":2926},{"alt":7,"src":2925},"http:\u002F\u002Ftest.mingrisoft.com\u002Fuploads\u002Fres_doc\u002FPython\u002F20\u002F101\u002F9944818140306101113.files\u002Fimage011.png",[],{"type":28,"value":2928},"",{"type":18,"tag":228,"props":2930,"children":2932},{"code":2931,"language":231,"meta":7,"className":232,"style":7},"for i in range(0xf035,0xf045):             #设置字符集编码的区间，输出多个特殊符号  \n    print(chr(i),end=\",\")\n",[2933],{"type":18,"tag":235,"props":2934,"children":2935},{"__ignoreMap":7},[2936,2944],{"type":18,"tag":239,"props":2937,"children":2938},{"class":241,"line":242},[2939],{"type":18,"tag":239,"props":2940,"children":2941},{},[2942],{"type":28,"value":2943},"for i in range(0xf035,0xf045):             #设置字符集编码的区间，输出多个特殊符号  \n",{"type":18,"tag":239,"props":2945,"children":2946},{"class":241,"line":251},[2947],{"type":18,"tag":239,"props":2948,"children":2949},{},[2950],{"type":28,"value":2951},"    print(chr(i),end=\",\")\n",{"type":18,"tag":31,"props":2953,"children":2954},{},[2955,2956,2960],{"type":28,"value":2891},{"type":18,"tag":2779,"props":2957,"children":2959},{"alt":7,"src":2958},"http:\u002F\u002Ftest.mingrisoft.com\u002Fuploads\u002Fres_doc\u002FPython\u002F20\u002F101\u002F9944818140306101113.files\u002Fimage013.jpg",[],{"type":28,"value":2961},"",{"type":18,"tag":31,"props":2963,"children":2964},{},[2965],{"type":28,"value":2966},"如果知道十进制字符编码的值也可以很方便的输入特殊字符。如要输入“←”，只要知道该符号的十进制字符编码“8592”，具体特殊字符编码十进制对照表如表1、表2所示。编写代码：",{"type":18,"tag":228,"props":2968,"children":2970},{"code":2969,"language":231,"meta":7,"className":232,"style":7},"print(chr(8592))\n",[2971],{"type":18,"tag":235,"props":2972,"children":2973},{"__ignoreMap":7},[2974],{"type":18,"tag":239,"props":2975,"children":2976},{"class":241,"line":242},[2977],{"type":18,"tag":239,"props":2978,"children":2979},{},[2980],{"type":28,"value":2969},{"type":18,"tag":31,"props":2982,"children":2983},{},[2984],{"type":28,"value":2985},"输出结果为：←",{"type":18,"tag":31,"props":2987,"children":2988},{},[2989],{"type":18,"tag":2779,"props":2990,"children":2993},{"alt":2991,"src":2992},"Pasted image 20250812092303","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250812092303.png",[],{"type":18,"tag":1483,"props":2995,"children":2997},{"id":2996},"锦囊05-将多次输出内容到一行",[2998],{"type":28,"value":2999},"锦囊05  将多次输出内容到一行",{"type":18,"tag":31,"props":3001,"children":3002},{},[3003,3005,3010,3012,3017,3019,3024,3026,3031,3033,3038,3039,3045],{"type":28,"value":3004},"Python中，",{"type":18,"tag":235,"props":3006,"children":3008},{"className":3007},[],[3009],{"type":28,"value":1052},{"type":28,"value":3011},"函数默认输出结束后以换行结束，即",{"type":18,"tag":235,"props":3013,"children":3015},{"className":3014},[],[3016],{"type":28,"value":1564},{"type":28,"value":3018},"的默认值是换行符",{"type":18,"tag":235,"props":3020,"children":3022},{"className":3021},[],[3023],{"type":28,"value":1572},{"type":28,"value":3025},"，打印完会跳到新行。如果打印完成不换行，只需将end设置成其他字符串，如",{"type":18,"tag":235,"props":3027,"children":3029},{"className":3028},[],[3030],{"type":28,"value":1580},{"type":28,"value":3032}," 、",{"type":18,"tag":235,"props":3034,"children":3036},{"className":3035},[],[3037],{"type":28,"value":1588},{"type":28,"value":660},{"type":18,"tag":235,"props":3040,"children":3042},{"className":3041},[],[3043],{"type":28,"value":3044},"《",{"type":28,"value":3046},"等字符。下面是将数字0~9输出到一行显示，代码如下：",{"type":18,"tag":228,"props":3048,"children":3050},{"code":3049,"language":231,"meta":7,"className":232,"style":7},"for x in range(0, 10):          # 设置输出内容区间为0~9  \n     print(x, end=' ')          # 输出数字用空格间隔输出到一行\n",[3051],{"type":18,"tag":235,"props":3052,"children":3053},{"__ignoreMap":7},[3054,3062],{"type":18,"tag":239,"props":3055,"children":3056},{"class":241,"line":242},[3057],{"type":18,"tag":239,"props":3058,"children":3059},{},[3060],{"type":28,"value":3061},"for x in range(0, 10):          # 设置输出内容区间为0~9  \n",{"type":18,"tag":239,"props":3063,"children":3064},{"class":241,"line":251},[3065],{"type":18,"tag":239,"props":3066,"children":3067},{},[3068],{"type":28,"value":3069},"     print(x, end=' ')          # 输出数字用空格间隔输出到一行\n",{"type":18,"tag":31,"props":3071,"children":3072},{},[3073],{"type":28,"value":1817},{"type":18,"tag":228,"props":3075,"children":3077},{"code":3076},"0 1 2 3 4 5 6 7 8 9 \n",[3078],{"type":18,"tag":235,"props":3079,"children":3080},{"__ignoreMap":7},[3081],{"type":28,"value":3076},{"type":18,"tag":228,"props":3083,"children":3085},{"code":3084,"language":231,"meta":7,"className":232,"style":7},"for x in range(0, 10):          # 置输出内容区间为0~9  \n     print(x, end='+')          # 输出数字用加号连接  \nprint(\"? = 100\")                # 输出结果和原输入内容形成计算题\n",[3086],{"type":18,"tag":235,"props":3087,"children":3088},{"__ignoreMap":7},[3089,3097,3105],{"type":18,"tag":239,"props":3090,"children":3091},{"class":241,"line":242},[3092],{"type":18,"tag":239,"props":3093,"children":3094},{},[3095],{"type":28,"value":3096},"for x in range(0, 10):          # 置输出内容区间为0~9  \n",{"type":18,"tag":239,"props":3098,"children":3099},{"class":241,"line":251},[3100],{"type":18,"tag":239,"props":3101,"children":3102},{},[3103],{"type":28,"value":3104},"     print(x, end='+')          # 输出数字用加号连接  \n",{"type":18,"tag":239,"props":3106,"children":3107},{"class":241,"line":396},[3108],{"type":18,"tag":239,"props":3109,"children":3110},{},[3111],{"type":28,"value":3112},"print(\"? = 100\")                # 输出结果和原输入内容形成计算题\n",{"type":18,"tag":31,"props":3114,"children":3115},{},[3116],{"type":28,"value":1817},{"type":18,"tag":228,"props":3118,"children":3120},{"code":3119},"0+1+2+3+4+5+6+7+8+9+? = 100\n",[3121],{"type":18,"tag":235,"props":3122,"children":3123},{"__ignoreMap":7},[3124],{"type":28,"value":3119},{"type":18,"tag":1483,"props":3126,"children":3128},{"id":3127},"锦囊06-指定位数编号输出",[3129],{"type":28,"value":3130},"锦囊06  指定位数编号输出",{"type":18,"tag":31,"props":3132,"children":3133},{},[3134,3140],{"type":18,"tag":235,"props":3135,"children":3137},{"className":3136},[],[3138],{"type":28,"value":3139},"zfill()",{"type":28,"value":3141},"函数可按指定位数输出固定位数的数据编号，如将输入的数字格式化为5位编号输出，代码如下：",{"type":18,"tag":228,"props":3143,"children":3145},{"code":3144,"language":231,"meta":7,"className":232,"style":7},"instr=input('请输入一个数字：')  \nprint (instr.zfill(5))        # 输出5位数字编号\n",[3146],{"type":18,"tag":235,"props":3147,"children":3148},{"__ignoreMap":7},[3149,3157],{"type":18,"tag":239,"props":3150,"children":3151},{"class":241,"line":242},[3152],{"type":18,"tag":239,"props":3153,"children":3154},{},[3155],{"type":28,"value":3156},"instr=input('请输入一个数字：')  \n",{"type":18,"tag":239,"props":3158,"children":3159},{"class":241,"line":251},[3160],{"type":18,"tag":239,"props":3161,"children":3162},{},[3163],{"type":28,"value":3164},"print (instr.zfill(5))        # 输出5位数字编号\n",{"type":18,"tag":31,"props":3166,"children":3167},{},[3168],{"type":28,"value":3169},"运行程序，输入一个数字，将会格式化为5位编号，如图所示。",{"type":18,"tag":31,"props":3171,"children":3172},{},[3173],{"type":18,"tag":2779,"props":3174,"children":3177},{"alt":3175,"src":3176},"Pasted image 20250812094041","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250812094041.png",[],{"type":18,"tag":31,"props":3179,"children":3180},{},[3181],{"type":28,"value":3182},"如果要循环输出固定位数的数字编号，该怎么输出呢？只需使用循环语句，即可方便的输出，代码如下：",{"type":18,"tag":228,"props":3184,"children":3186},{"code":3185,"language":231,"meta":7,"className":232,"style":7},"for i in range(1,20):         # 设置输出区间为1~19  \n    n=str(i)                  # 将数字转为字符串  \n    s = n.zfill(3)            # 将格式化的编号赋值给s  \n    print (s)                 # 输出s\n",[3187],{"type":18,"tag":235,"props":3188,"children":3189},{"__ignoreMap":7},[3190,3198,3206,3214],{"type":18,"tag":239,"props":3191,"children":3192},{"class":241,"line":242},[3193],{"type":18,"tag":239,"props":3194,"children":3195},{},[3196],{"type":28,"value":3197},"for i in range(1,20):         # 设置输出区间为1~19  \n",{"type":18,"tag":239,"props":3199,"children":3200},{"class":241,"line":251},[3201],{"type":18,"tag":239,"props":3202,"children":3203},{},[3204],{"type":28,"value":3205},"    n=str(i)                  # 将数字转为字符串  \n",{"type":18,"tag":239,"props":3207,"children":3208},{"class":241,"line":396},[3209],{"type":18,"tag":239,"props":3210,"children":3211},{},[3212],{"type":28,"value":3213},"    s = n.zfill(3)            # 将格式化的编号赋值给s  \n",{"type":18,"tag":239,"props":3215,"children":3216},{"class":241,"line":405},[3217],{"type":18,"tag":239,"props":3218,"children":3219},{},[3220],{"type":28,"value":3221},"    print (s)                 # 输出s\n",{"type":18,"tag":31,"props":3223,"children":3224},{},[3225],{"type":28,"value":1817},{"type":18,"tag":228,"props":3227,"children":3229},{"code":3228},"001\n002\n003\n…\n",[3230],{"type":18,"tag":235,"props":3231,"children":3232},{"__ignoreMap":7},[3233],{"type":28,"value":3228},{"type":18,"tag":31,"props":3235,"children":3236},{},[3237,3239,3244,3246,3252],{"type":28,"value":3238},"除了",{"type":18,"tag":235,"props":3240,"children":3242},{"className":3241},[],[3243],{"type":28,"value":3139},{"type":28,"value":3245},"函数，",{"type":18,"tag":235,"props":3247,"children":3249},{"className":3248},[],[3250],{"type":28,"value":3251},"format()",{"type":28,"value":3253},"函数也可以实现强大的格式化输出，如：",{"type":18,"tag":228,"props":3255,"children":3257},{"code":3256,"language":231,"meta":7,"className":232,"style":7},"instr='112'  \nprint (format(instr,'0>5'))        # 输出5位数字编号  \nprint (format(instr,'*>5'))        # 输出5位字符串，空位用*填充  \nprint (format(instr,'>5'))         #  输出5位字符串，空位用空格填充\n",[3258],{"type":18,"tag":235,"props":3259,"children":3260},{"__ignoreMap":7},[3261,3269,3277,3285],{"type":18,"tag":239,"props":3262,"children":3263},{"class":241,"line":242},[3264],{"type":18,"tag":239,"props":3265,"children":3266},{},[3267],{"type":28,"value":3268},"instr='112'  \n",{"type":18,"tag":239,"props":3270,"children":3271},{"class":241,"line":251},[3272],{"type":18,"tag":239,"props":3273,"children":3274},{},[3275],{"type":28,"value":3276},"print (format(instr,'0>5'))        # 输出5位数字编号  \n",{"type":18,"tag":239,"props":3278,"children":3279},{"class":241,"line":396},[3280],{"type":18,"tag":239,"props":3281,"children":3282},{},[3283],{"type":28,"value":3284},"print (format(instr,'*>5'))        # 输出5位字符串，空位用*填充  \n",{"type":18,"tag":239,"props":3286,"children":3287},{"class":241,"line":405},[3288],{"type":18,"tag":239,"props":3289,"children":3290},{},[3291],{"type":28,"value":3292},"print (format(instr,'>5'))         #  输出5位字符串，空位用空格填充\n",{"type":18,"tag":31,"props":3294,"children":3295},{},[3296],{"type":28,"value":1817},{"type":18,"tag":228,"props":3298,"children":3300},{"code":3299},"00112\n**112\n  112\n",[3301],{"type":18,"tag":235,"props":3302,"children":3303},{"__ignoreMap":7},[3304],{"type":28,"value":3299},{"type":18,"tag":1483,"props":3306,"children":3308},{"id":3307},"锦囊07-进制输出",[3309],{"type":28,"value":3310},"锦囊07  进制输出",{"type":18,"tag":31,"props":3312,"children":3313},{},[3314,3316,3321],{"type":28,"value":3315},"输出进制数可以采用操作符、进制转换函数和格式化函数",{"type":18,"tag":235,"props":3317,"children":3319},{"className":3318},[],[3320],{"type":28,"value":3251},{"type":28,"value":3322},"来实现。下面通过代码与注释介绍应用。",{"type":18,"tag":228,"props":3324,"children":3326},{"code":3325,"language":231,"meta":7,"className":232,"style":7},"x=112  \nprint(\"%o\"%x)                # 使用操作符输出八进制数  \nprint(\"%x\"%x)                # 使用操作符输出十六进制数  \nprint(\"nHex = %x,nDec = %d,nOct = %o\" %(x,x,x)) # 输出十六进制、十进制、八进制数  \nprint(bin(x))                # 使用bin()函数输出二进制数  \nprint(oct(x))                # 使用oct()函数输出八进制数  \nprint(hex(x))                # 使用hex()函数输出十六进制数\n",[3327],{"type":18,"tag":235,"props":3328,"children":3329},{"__ignoreMap":7},[3330,3338,3346,3354,3362,3370,3378],{"type":18,"tag":239,"props":3331,"children":3332},{"class":241,"line":242},[3333],{"type":18,"tag":239,"props":3334,"children":3335},{},[3336],{"type":28,"value":3337},"x=112  \n",{"type":18,"tag":239,"props":3339,"children":3340},{"class":241,"line":251},[3341],{"type":18,"tag":239,"props":3342,"children":3343},{},[3344],{"type":28,"value":3345},"print(\"%o\"%x)                # 使用操作符输出八进制数  \n",{"type":18,"tag":239,"props":3347,"children":3348},{"class":241,"line":396},[3349],{"type":18,"tag":239,"props":3350,"children":3351},{},[3352],{"type":28,"value":3353},"print(\"%x\"%x)                # 使用操作符输出十六进制数  \n",{"type":18,"tag":239,"props":3355,"children":3356},{"class":241,"line":405},[3357],{"type":18,"tag":239,"props":3358,"children":3359},{},[3360],{"type":28,"value":3361},"print(\"nHex = %x,nDec = %d,nOct = %o\" %(x,x,x)) # 输出十六进制、十进制、八进制数  \n",{"type":18,"tag":239,"props":3363,"children":3364},{"class":241,"line":415},[3365],{"type":18,"tag":239,"props":3366,"children":3367},{},[3368],{"type":28,"value":3369},"print(bin(x))                # 使用bin()函数输出二进制数  \n",{"type":18,"tag":239,"props":3371,"children":3372},{"class":241,"line":424},[3373],{"type":18,"tag":239,"props":3374,"children":3375},{},[3376],{"type":28,"value":3377},"print(oct(x))                # 使用oct()函数输出八进制数  \n",{"type":18,"tag":239,"props":3379,"children":3380},{"class":241,"line":732},[3381],{"type":18,"tag":239,"props":3382,"children":3383},{},[3384],{"type":28,"value":3385},"print(hex(x))                # 使用hex()函数输出十六进制数\n",{"type":18,"tag":31,"props":3387,"children":3388},{},[3389],{"type":28,"value":1817},{"type":18,"tag":228,"props":3391,"children":3393},{"code":3392},"160\n70\nnHex = 70,nDec = 112,nOct = 160\n0b1110000\n0o160\n0x70\n",[3394],{"type":18,"tag":235,"props":3395,"children":3396},{"__ignoreMap":7},[3397],{"type":28,"value":3392},{"type":18,"tag":228,"props":3399,"children":3401},{"code":3400,"language":231,"meta":7,"className":232,"style":7},"x = 112  \nprint(\"{0:d}\".format(x))            # 使用format函数输出十进制数  \nprint(\"{0:x}\".format(x))            # 使用format函数输出十六进制数  \nprint(\"{0:o}\".format(x))            # 使用format函数输出八进制数  \nprint(\"{0:b}\".format(x))            # 使用format函数输出二进制数  \nprint(\"int: {0:d};  hex: {0:x};  oct: {0:o};  bin: {0:b}\".format(x)) #综合输出进制数  \n# 综合输出带符号的各进制数  \nprint(\"二进制: {0:#b}; 八进制: {0:#o} ;十进制: {0:#d};  十六进制: {0:#x}\".format(x))\n",[3402],{"type":18,"tag":235,"props":3403,"children":3404},{"__ignoreMap":7},[3405,3413,3421,3429,3437,3445,3453,3461],{"type":18,"tag":239,"props":3406,"children":3407},{"class":241,"line":242},[3408],{"type":18,"tag":239,"props":3409,"children":3410},{},[3411],{"type":28,"value":3412},"x = 112  \n",{"type":18,"tag":239,"props":3414,"children":3415},{"class":241,"line":251},[3416],{"type":18,"tag":239,"props":3417,"children":3418},{},[3419],{"type":28,"value":3420},"print(\"{0:d}\".format(x))            # 使用format函数输出十进制数  \n",{"type":18,"tag":239,"props":3422,"children":3423},{"class":241,"line":396},[3424],{"type":18,"tag":239,"props":3425,"children":3426},{},[3427],{"type":28,"value":3428},"print(\"{0:x}\".format(x))            # 使用format函数输出十六进制数  \n",{"type":18,"tag":239,"props":3430,"children":3431},{"class":241,"line":405},[3432],{"type":18,"tag":239,"props":3433,"children":3434},{},[3435],{"type":28,"value":3436},"print(\"{0:o}\".format(x))            # 使用format函数输出八进制数  \n",{"type":18,"tag":239,"props":3438,"children":3439},{"class":241,"line":415},[3440],{"type":18,"tag":239,"props":3441,"children":3442},{},[3443],{"type":28,"value":3444},"print(\"{0:b}\".format(x))            # 使用format函数输出二进制数  \n",{"type":18,"tag":239,"props":3446,"children":3447},{"class":241,"line":424},[3448],{"type":18,"tag":239,"props":3449,"children":3450},{},[3451],{"type":28,"value":3452},"print(\"int: {0:d};  hex: {0:x};  oct: {0:o};  bin: {0:b}\".format(x)) #综合输出进制数  \n",{"type":18,"tag":239,"props":3454,"children":3455},{"class":241,"line":732},[3456],{"type":18,"tag":239,"props":3457,"children":3458},{},[3459],{"type":28,"value":3460},"# 综合输出带符号的各进制数  \n",{"type":18,"tag":239,"props":3462,"children":3463},{"class":241,"line":1269},[3464],{"type":18,"tag":239,"props":3465,"children":3466},{},[3467],{"type":28,"value":3468},"print(\"二进制: {0:#b}; 八进制: {0:#o} ;十进制: {0:#d};  十六进制: {0:#x}\".format(x))\n",{"type":18,"tag":31,"props":3470,"children":3471},{},[3472],{"type":28,"value":1817},{"type":18,"tag":228,"props":3474,"children":3476},{"code":3475},"112\n70\n160\n1110000\nint: 112;  hex: 70;  oct: 160;  bin: 1110000\n二进制: 0b1110000; 八进制: 0o160 ;十进制: 112;  十六进制: 0x70\n",[3477],{"type":18,"tag":235,"props":3478,"children":3479},{"__ignoreMap":7},[3480],{"type":28,"value":3475},{"type":18,"tag":1483,"props":3482,"children":3484},{"id":3483},"锦囊08-输出彩色文字或背景",[3485],{"type":28,"value":3486},"锦囊08  输出彩色文字或背景",{"type":18,"tag":31,"props":3488,"children":3489},{},[3490,3492,3498],{"type":28,"value":3491},"在PyCharm下要输出要输出彩色，可以在输出前设置显示方式，格式为：",{"type":18,"tag":235,"props":3493,"children":3495},{"className":3494},[],[3496],{"type":28,"value":3497},"\\033[显示方式;前景色;背景色m",{"type":28,"value":3499},"。显示方式，前景色，背景色是可选参数，可以只写其中的某一个；显示方式、前景色、背景色如图所示。",{"type":18,"tag":228,"props":3501,"children":3503},{"code":3502,"language":231,"meta":7,"className":232,"style":7},"print('\\033[1;31m Stay hungry,Stay foolish!\\033[0m')   # 红色前景色输出名言  \nprint('\\033[1;32;45m 求知若饥,虚心若愚!\\033[0m')   # 绿色前景色输出名言，背景色为紫色\n",[3504],{"type":18,"tag":235,"props":3505,"children":3506},{"__ignoreMap":7},[3507,3515],{"type":18,"tag":239,"props":3508,"children":3509},{"class":241,"line":242},[3510],{"type":18,"tag":239,"props":3511,"children":3512},{},[3513],{"type":28,"value":3514},"print('\\033[1;31m Stay hungry,Stay foolish!\\033[0m')   # 红色前景色输出名言  \n",{"type":18,"tag":239,"props":3516,"children":3517},{"class":241,"line":251},[3518],{"type":18,"tag":239,"props":3519,"children":3520},{},[3521],{"type":28,"value":3522},"print('\\033[1;32;45m 求知若饥,虚心若愚!\\033[0m')   # 绿色前景色输出名言，背景色为紫色\n",{"type":18,"tag":31,"props":3524,"children":3525},{},[3526],{"type":28,"value":3527},"程序运行结果如图所示。",{"type":18,"tag":31,"props":3529,"children":3530},{},[3531],{"type":18,"tag":2779,"props":3532,"children":3535},{"alt":3533,"src":3534},"Pasted image 20250812095053","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250812095053.png",[],{"type":18,"tag":228,"props":3537,"children":3539},{"code":3538,"language":231,"meta":7,"className":232,"style":7},"print('go big or go\\033[1;35m home \\033[0m!')   # 设置文字中home 紫色前景色显示  \n# 设置文字中home绿色前景色，黄色背景色显示  \nprint('go big or go\\033[1;32;43m home \\033[0m!')  \nprint('\\033[1;31;44mgo big or go home \\033[0m')  # 设置文字红色前景色，蓝色背景色显示\n",[3540],{"type":18,"tag":235,"props":3541,"children":3542},{"__ignoreMap":7},[3543,3551,3559,3567],{"type":18,"tag":239,"props":3544,"children":3545},{"class":241,"line":242},[3546],{"type":18,"tag":239,"props":3547,"children":3548},{},[3549],{"type":28,"value":3550},"print('go big or go\\033[1;35m home \\033[0m!')   # 设置文字中home 紫色前景色显示  \n",{"type":18,"tag":239,"props":3552,"children":3553},{"class":241,"line":251},[3554],{"type":18,"tag":239,"props":3555,"children":3556},{},[3557],{"type":28,"value":3558},"# 设置文字中home绿色前景色，黄色背景色显示  \n",{"type":18,"tag":239,"props":3560,"children":3561},{"class":241,"line":396},[3562],{"type":18,"tag":239,"props":3563,"children":3564},{},[3565],{"type":28,"value":3566},"print('go big or go\\033[1;32;43m home \\033[0m!')  \n",{"type":18,"tag":239,"props":3568,"children":3569},{"class":241,"line":405},[3570],{"type":18,"tag":239,"props":3571,"children":3572},{},[3573],{"type":28,"value":3574},"print('\\033[1;31;44mgo big or go home \\033[0m')  # 设置文字红色前景色，蓝色背景色显示\n",{"type":18,"tag":31,"props":3576,"children":3577},{},[3578],{"type":28,"value":3579},"程序的运行结果如图所示。",{"type":18,"tag":31,"props":3581,"children":3582},{},[3583],{"type":18,"tag":2779,"props":3584,"children":3587},{"alt":3585,"src":3586},"Pasted image 20250812095212","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250812095212.png",[],{"type":18,"tag":31,"props":3589,"children":3590},{},[3591],{"type":18,"tag":2779,"props":3592,"children":3595},{"alt":3593,"src":3594},"Pasted image 20250812095901","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250812095901.png",[],{"type":18,"tag":1483,"props":3597,"children":3599},{"id":3598},"锦囊09-对齐输出数据",[3600],{"type":28,"value":3601},"锦囊09  对齐输出数据",{"type":18,"tag":31,"props":3603,"children":3604},{},[3605,3607,3613,3614,3620,3621,3626,3628,3633],{"type":28,"value":3606},"对齐数据可以使用",{"type":18,"tag":235,"props":3608,"children":3610},{"className":3609},[],[3611],{"type":28,"value":3612},"rjust",{"type":28,"value":1700},{"type":18,"tag":235,"props":3615,"children":3617},{"className":3616},[],[3618],{"type":28,"value":3619},"ljust",{"type":28,"value":100},{"type":18,"tag":235,"props":3622,"children":3624},{"className":3623},[],[3625],{"type":28,"value":464},{"type":28,"value":3627},"来实现。也可以使用格式化函数",{"type":18,"tag":235,"props":3629,"children":3631},{"className":3630},[],[3632],{"type":28,"value":3251},{"type":28,"value":3634},"实现，下面通过代码和注释来实现。",{"type":18,"tag":228,"props":3636,"children":3638},{"code":3637,"language":231,"meta":7,"className":232,"style":7},"team=\"格林兰岛\"  \nprint(team.ljust(10))              #左对齐字符串，用空格号占位  \nprint(team.ljust(10,'*'))          #左对齐字符串，用*号占位  \nprint(team.rjust(10,'*'))          #右对齐字符串，用*号占位  \nprint(team.rjust(10))              #右对齐字符串，用空格号占位  \nprint(team.center(10))             #中间对齐字符串，用空格号占位  \nprint(team.center(10,'*'))         #中间对齐字符串，用*号占位\n",[3639],{"type":18,"tag":235,"props":3640,"children":3641},{"__ignoreMap":7},[3642,3650,3658,3666,3674,3682,3690],{"type":18,"tag":239,"props":3643,"children":3644},{"class":241,"line":242},[3645],{"type":18,"tag":239,"props":3646,"children":3647},{},[3648],{"type":28,"value":3649},"team=\"格林兰岛\"  \n",{"type":18,"tag":239,"props":3651,"children":3652},{"class":241,"line":251},[3653],{"type":18,"tag":239,"props":3654,"children":3655},{},[3656],{"type":28,"value":3657},"print(team.ljust(10))              #左对齐字符串，用空格号占位  \n",{"type":18,"tag":239,"props":3659,"children":3660},{"class":241,"line":396},[3661],{"type":18,"tag":239,"props":3662,"children":3663},{},[3664],{"type":28,"value":3665},"print(team.ljust(10,'*'))          #左对齐字符串，用*号占位  \n",{"type":18,"tag":239,"props":3667,"children":3668},{"class":241,"line":405},[3669],{"type":18,"tag":239,"props":3670,"children":3671},{},[3672],{"type":28,"value":3673},"print(team.rjust(10,'*'))          #右对齐字符串，用*号占位  \n",{"type":18,"tag":239,"props":3675,"children":3676},{"class":241,"line":415},[3677],{"type":18,"tag":239,"props":3678,"children":3679},{},[3680],{"type":28,"value":3681},"print(team.rjust(10))              #右对齐字符串，用空格号占位  \n",{"type":18,"tag":239,"props":3683,"children":3684},{"class":241,"line":424},[3685],{"type":18,"tag":239,"props":3686,"children":3687},{},[3688],{"type":28,"value":3689},"print(team.center(10))             #中间对齐字符串，用空格号占位  \n",{"type":18,"tag":239,"props":3691,"children":3692},{"class":241,"line":732},[3693],{"type":18,"tag":239,"props":3694,"children":3695},{},[3696],{"type":28,"value":3697},"print(team.center(10,'*'))         #中间对齐字符串，用*号占位\n",{"type":18,"tag":31,"props":3699,"children":3700},{},[3701],{"type":28,"value":1817},{"type":18,"tag":228,"props":3703,"children":3705},{"code":3704},"格林兰岛      \n格林兰岛******\n******格林兰岛\n      格林兰岛\n   格林兰岛   \n***格林兰岛***\n",[3706],{"type":18,"tag":235,"props":3707,"children":3708},{"__ignoreMap":7},[3709],{"type":28,"value":3704},{"type":18,"tag":228,"props":3711,"children":3713},{"code":3712,"language":231,"meta":7,"className":232,"style":7},"s=\"多特蒙德\"  \nprint(format(s,'*>20'))  # 右对齐字符串，“*”为号占位符，“>”为右对齐符号，20宽度  \nprint(format(s,'#\u003C20'))  # 左对齐字符串，“#”为号占位符，“\u003C”为左对齐符号，20宽度  \nprint(format(s,' ^20'))  # 中间对齐字符串，空格“ ”为占位符，“^”对齐符号，20宽度\n",[3714],{"type":18,"tag":235,"props":3715,"children":3716},{"__ignoreMap":7},[3717,3725,3733,3741],{"type":18,"tag":239,"props":3718,"children":3719},{"class":241,"line":242},[3720],{"type":18,"tag":239,"props":3721,"children":3722},{},[3723],{"type":28,"value":3724},"s=\"多特蒙德\"  \n",{"type":18,"tag":239,"props":3726,"children":3727},{"class":241,"line":251},[3728],{"type":18,"tag":239,"props":3729,"children":3730},{},[3731],{"type":28,"value":3732},"print(format(s,'*>20'))  # 右对齐字符串，“*”为号占位符，“>”为右对齐符号，20宽度  \n",{"type":18,"tag":239,"props":3734,"children":3735},{"class":241,"line":396},[3736],{"type":18,"tag":239,"props":3737,"children":3738},{},[3739],{"type":28,"value":3740},"print(format(s,'#\u003C20'))  # 左对齐字符串，“#”为号占位符，“\u003C”为左对齐符号，20宽度  \n",{"type":18,"tag":239,"props":3742,"children":3743},{"class":241,"line":405},[3744],{"type":18,"tag":239,"props":3745,"children":3746},{},[3747],{"type":28,"value":3748},"print(format(s,' ^20'))  # 中间对齐字符串，空格“ ”为占位符，“^”对齐符号，20宽度\n",{"type":18,"tag":31,"props":3750,"children":3751},{},[3752],{"type":28,"value":1817},{"type":18,"tag":228,"props":3754,"children":3756},{"code":3755},"****************多特蒙德\n多特蒙德################\n        多特蒙德        \n",[3757],{"type":18,"tag":235,"props":3758,"children":3759},{"__ignoreMap":7},[3760],{"type":28,"value":3755},{"type":18,"tag":228,"props":3762,"children":3764},{"code":3763,"language":231,"meta":7,"className":232,"style":7},"car=[ [1,\"奔驰\",489163],[2,\"宝马\",455051] ,[3,\"奥迪\",445300]]  \n  \nfor item in car:                                          # 循环读取列表数据  \n    tup='{0:0>3}\\t{1:*^12}\\t{2:$>12.2f}'                # 设置对其格式和占位符  \n    print(tup.format(item[0],item[1],float(item[2])))  # 输出数据未设置格式\n",[3765],{"type":18,"tag":235,"props":3766,"children":3767},{"__ignoreMap":7},[3768,3776,3783,3791,3799],{"type":18,"tag":239,"props":3769,"children":3770},{"class":241,"line":242},[3771],{"type":18,"tag":239,"props":3772,"children":3773},{},[3774],{"type":28,"value":3775},"car=[ [1,\"奔驰\",489163],[2,\"宝马\",455051] ,[3,\"奥迪\",445300]]  \n",{"type":18,"tag":239,"props":3777,"children":3778},{"class":241,"line":251},[3779],{"type":18,"tag":239,"props":3780,"children":3781},{},[3782],{"type":28,"value":2476},{"type":18,"tag":239,"props":3784,"children":3785},{"class":241,"line":396},[3786],{"type":18,"tag":239,"props":3787,"children":3788},{},[3789],{"type":28,"value":3790},"for item in car:                                          # 循环读取列表数据  \n",{"type":18,"tag":239,"props":3792,"children":3793},{"class":241,"line":405},[3794],{"type":18,"tag":239,"props":3795,"children":3796},{},[3797],{"type":28,"value":3798},"    tup='{0:0>3}\\t{1:*^12}\\t{2:$>12.2f}'                # 设置对其格式和占位符  \n",{"type":18,"tag":239,"props":3800,"children":3801},{"class":241,"line":415},[3802],{"type":18,"tag":239,"props":3803,"children":3804},{},[3805],{"type":28,"value":3806},"    print(tup.format(item[0],item[1],float(item[2])))  # 输出数据未设置格式\n",{"type":18,"tag":31,"props":3808,"children":3809},{},[3810],{"type":28,"value":1817},{"type":18,"tag":228,"props":3812,"children":3814},{"code":3813},"001 *****奔驰*****    $$$489163.00\n002 *****宝马*****    $$$455051.00\n003 *****奥迪*****    $$$445300.00\n",[3815],{"type":18,"tag":235,"props":3816,"children":3817},{"__ignoreMap":7},[3818],{"type":28,"value":3813},{"type":18,"tag":1483,"props":3820,"children":3822},{"id":3821},"锦囊10-输出内容到文件",[3823],{"type":28,"value":3824},"锦囊10  输出内容到文件",{"type":18,"tag":31,"props":3826,"children":3827},{},[3828],{"type":28,"value":3829},"设置参数file为目标文件名称，即可输出需要输出的内容到文件。代码如下：",{"type":18,"tag":228,"props":3831,"children":3833},{"code":3832,"language":231,"meta":7,"className":232,"style":7},"fp = open('mingrisoft.txt','a+')                # 'a+'以读写模式打开文件  \ntext=\"go big or go home\"  \nprint(text,file=fp)                                   # 输出到文件中  \nfp.close()\n",[3834],{"type":18,"tag":235,"props":3835,"children":3836},{"__ignoreMap":7},[3837,3845,3853,3861],{"type":18,"tag":239,"props":3838,"children":3839},{"class":241,"line":242},[3840],{"type":18,"tag":239,"props":3841,"children":3842},{},[3843],{"type":28,"value":3844},"fp = open('mingrisoft.txt','a+')                # 'a+'以读写模式打开文件  \n",{"type":18,"tag":239,"props":3846,"children":3847},{"class":241,"line":251},[3848],{"type":18,"tag":239,"props":3849,"children":3850},{},[3851],{"type":28,"value":3852},"text=\"go big or go home\"  \n",{"type":18,"tag":239,"props":3854,"children":3855},{"class":241,"line":396},[3856],{"type":18,"tag":239,"props":3857,"children":3858},{},[3859],{"type":28,"value":3860},"print(text,file=fp)                                   # 输出到文件中  \n",{"type":18,"tag":239,"props":3862,"children":3863},{"class":241,"line":405},[3864],{"type":18,"tag":239,"props":3865,"children":3866},{},[3867],{"type":28,"value":3868},"fp.close()\n",{"type":18,"tag":31,"props":3870,"children":3871},{},[3872,3874,3880],{"type":28,"value":3873},"执行上面的代码后，将在程序所在目录下生成一个名称为",{"type":18,"tag":235,"props":3875,"children":3877},{"className":3876},[],[3878],{"type":28,"value":3879},"mingrisoft.txt",{"type":28,"value":3881},"的文件，该文件的内容为文字“go big or go home”。",{"type":18,"tag":31,"props":3883,"children":3884},{},[3885],{"type":18,"tag":35,"props":3886,"children":3887},{},[3888],{"type":28,"value":3889},"场景一：输出嵌套列表的数据",{"type":18,"tag":31,"props":3891,"children":3892},{},[3893],{"type":28,"value":3894},"对于复杂嵌套列表，如何格式化输出对应的数据呢？可以利用for循环读取数据，然后进行格式化处理，即可实现嵌套列表的格式化输出。代码如下：",{"type":18,"tag":228,"props":3896,"children":3898},{"code":3897,"language":231,"meta":7,"className":232,"style":7},"college=['1,哈佛大学,Harvard University,美国,100','2,斯坦福大学,Stanford University,美国,76.5','3,剑桥大学,University of Cambridge,英国,70.9','4,麻省理工学院,Massachusetts Institute of Technology,美国,70.4','5,加州大学-伯克利,University of California Berkeley,美国,69.1']  \n  \nprint(\"{0:\u003C3}\\t{1:\u003C12}\\t{2:\u003C31}\\t{3:\u003C4}\\t{4:\u003C6}\".format('排名','中文名称','英文名称','国家','分数'))  \n  \nfor item in college:  \n    line=item.split(',')  \n    tupl = '{0:0>3}\\t{1:\u003C12}\\t{2:\u003C38}\\t{3:\u003C4}\\t{4:>6.2f}'  \n    print(tupl.format(line[0],line[1],line[2],line[3],float(line[4])))\n",[3899],{"type":18,"tag":235,"props":3900,"children":3901},{"__ignoreMap":7},[3902,3910,3917,3925,3932,3940,3948,3956],{"type":18,"tag":239,"props":3903,"children":3904},{"class":241,"line":242},[3905],{"type":18,"tag":239,"props":3906,"children":3907},{},[3908],{"type":28,"value":3909},"college=['1,哈佛大学,Harvard University,美国,100','2,斯坦福大学,Stanford University,美国,76.5','3,剑桥大学,University of Cambridge,英国,70.9','4,麻省理工学院,Massachusetts Institute of Technology,美国,70.4','5,加州大学-伯克利,University of California Berkeley,美国,69.1']  \n",{"type":18,"tag":239,"props":3911,"children":3912},{"class":241,"line":251},[3913],{"type":18,"tag":239,"props":3914,"children":3915},{},[3916],{"type":28,"value":2476},{"type":18,"tag":239,"props":3918,"children":3919},{"class":241,"line":396},[3920],{"type":18,"tag":239,"props":3921,"children":3922},{},[3923],{"type":28,"value":3924},"print(\"{0:\u003C3}\\t{1:\u003C12}\\t{2:\u003C31}\\t{3:\u003C4}\\t{4:\u003C6}\".format('排名','中文名称','英文名称','国家','分数'))  \n",{"type":18,"tag":239,"props":3926,"children":3927},{"class":241,"line":405},[3928],{"type":18,"tag":239,"props":3929,"children":3930},{},[3931],{"type":28,"value":2476},{"type":18,"tag":239,"props":3933,"children":3934},{"class":241,"line":415},[3935],{"type":18,"tag":239,"props":3936,"children":3937},{},[3938],{"type":28,"value":3939},"for item in college:  \n",{"type":18,"tag":239,"props":3941,"children":3942},{"class":241,"line":424},[3943],{"type":18,"tag":239,"props":3944,"children":3945},{},[3946],{"type":28,"value":3947},"    line=item.split(',')  \n",{"type":18,"tag":239,"props":3949,"children":3950},{"class":241,"line":732},[3951],{"type":18,"tag":239,"props":3952,"children":3953},{},[3954],{"type":28,"value":3955},"    tupl = '{0:0>3}\\t{1:\u003C12}\\t{2:\u003C38}\\t{3:\u003C4}\\t{4:>6.2f}'  \n",{"type":18,"tag":239,"props":3957,"children":3958},{"class":241,"line":1269},[3959],{"type":18,"tag":239,"props":3960,"children":3961},{},[3962],{"type":28,"value":3963},"    print(tupl.format(line[0],line[1],line[2],line[3],float(line[4])))\n",{"type":18,"tag":31,"props":3965,"children":3966},{},[3967],{"type":28,"value":3968},"运行程序，输出效果如图所示。",{"type":18,"tag":31,"props":3970,"children":3971},{},[3972],{"type":18,"tag":2779,"props":3973,"children":3976},{"alt":3974,"src":3975},"Pasted image 20250812100720","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250812100720.png",[],{"type":18,"tag":31,"props":3978,"children":3979},{},[3980,3982,3988],{"type":28,"value":3981},"上面输出当中，采用了左对齐输出，输出时使用制表符",{"type":18,"tag":235,"props":3983,"children":3985},{"className":3984},[],[3986],{"type":28,"value":3987},"\\t",{"type":28,"value":3989},"进行对齐。如果要采用中间对齐方式，会出现对齐效果不佳的情况，这是因为中文字符和英文占据的宽度不同。空格采用中文的空格，可以很好地输出效果。",{"type":18,"tag":228,"props":3991,"children":3993},{"code":3992,"language":231,"meta":7,"className":232,"style":7},"college=['1,哈佛大学,Harvard University,美国,100','2,斯坦福大学,Stanford University,美国,76.5','3,剑桥大学,University of Cambridge,英国,70.9','4,麻省理工学院,Massachusetts Institute of Technology,美国,70.4','5,加州大学-伯克利,University of California Berkeley,美国,69.1']  \n  \nchn = chr(12288)  \nprint(chn)  \ntupl1='{0:\u003C3}\\t{1:'+chn+'^10}\\t{2:^30}\\t{3:^6}\\t{4:^6}'  \nprint(tupl1.format('排名','中文名称','英文名称','国家','分数'))  \nfor item in college:  \n    line=item.split(',')  \n    tupl2 = '{0:0\u003C3}\\t{1:'+chn+'^10}\\t{2:^38}\\t{3:^6}\\t{4:6.2f}'  \n    print(tupl2.format(line[0],line[1],line[2],line[3],float(line[4])))\n",[3994],{"type":18,"tag":235,"props":3995,"children":3996},{"__ignoreMap":7},[3997,4004,4011,4019,4027,4035,4043,4050,4057,4065],{"type":18,"tag":239,"props":3998,"children":3999},{"class":241,"line":242},[4000],{"type":18,"tag":239,"props":4001,"children":4002},{},[4003],{"type":28,"value":3909},{"type":18,"tag":239,"props":4005,"children":4006},{"class":241,"line":251},[4007],{"type":18,"tag":239,"props":4008,"children":4009},{},[4010],{"type":28,"value":2476},{"type":18,"tag":239,"props":4012,"children":4013},{"class":241,"line":396},[4014],{"type":18,"tag":239,"props":4015,"children":4016},{},[4017],{"type":28,"value":4018},"chn = chr(12288)  \n",{"type":18,"tag":239,"props":4020,"children":4021},{"class":241,"line":405},[4022],{"type":18,"tag":239,"props":4023,"children":4024},{},[4025],{"type":28,"value":4026},"print(chn)  \n",{"type":18,"tag":239,"props":4028,"children":4029},{"class":241,"line":415},[4030],{"type":18,"tag":239,"props":4031,"children":4032},{},[4033],{"type":28,"value":4034},"tupl1='{0:\u003C3}\\t{1:'+chn+'^10}\\t{2:^30}\\t{3:^6}\\t{4:^6}'  \n",{"type":18,"tag":239,"props":4036,"children":4037},{"class":241,"line":424},[4038],{"type":18,"tag":239,"props":4039,"children":4040},{},[4041],{"type":28,"value":4042},"print(tupl1.format('排名','中文名称','英文名称','国家','分数'))  \n",{"type":18,"tag":239,"props":4044,"children":4045},{"class":241,"line":732},[4046],{"type":18,"tag":239,"props":4047,"children":4048},{},[4049],{"type":28,"value":3939},{"type":18,"tag":239,"props":4051,"children":4052},{"class":241,"line":1269},[4053],{"type":18,"tag":239,"props":4054,"children":4055},{},[4056],{"type":28,"value":3947},{"type":18,"tag":239,"props":4058,"children":4059},{"class":241,"line":1444},[4060],{"type":18,"tag":239,"props":4061,"children":4062},{},[4063],{"type":28,"value":4064},"    tupl2 = '{0:0\u003C3}\\t{1:'+chn+'^10}\\t{2:^38}\\t{3:^6}\\t{4:6.2f}'  \n",{"type":18,"tag":239,"props":4066,"children":4067},{"class":241,"line":1453},[4068],{"type":18,"tag":239,"props":4069,"children":4070},{},[4071],{"type":28,"value":4072},"    print(tupl2.format(line[0],line[1],line[2],line[3],float(line[4])))\n",{"type":18,"tag":31,"props":4074,"children":4075},{},[4076],{"type":28,"value":3968},{"type":18,"tag":31,"props":4078,"children":4079},{},[4080],{"type":18,"tag":2779,"props":4081,"children":4084},{"alt":4082,"src":4083},"Pasted image 20250812101122","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250812101122.png",[],{"type":18,"tag":31,"props":4086,"children":4087},{},[4088],{"type":18,"tag":35,"props":4089,"children":4090},{},[4091],{"type":28,"value":4092},"场景二：中英文多列对齐输出",{"type":18,"tag":31,"props":4094,"children":4095},{},[4096],{"type":28,"value":4097},"中英文多列对齐输出德国、法国、英国2018年汽车销量数据。读取多个列表的数据，对数据输出时，如果进行格式化处理，输出不对齐，影响输出效果。代码如下：",{"type":18,"tag":228,"props":4099,"children":4101},{"code":4100,"language":231,"meta":7,"className":232,"style":7},"gem=[[\"大众\",643518],[\"奔驰\",319163],[\"宝马\",265051],[\"福特\",252323],[\"雪铁龙\",227967],[\"奥迪\",255300]]  \nfra=[[\"雪铁龙\", 698985],[\"雷诺\",547704],[\"大众\",259268],[\"福特\",82633],[\"宝马\",84931],[\"奔驰\",73254]]  \neng=[[\"福特\",254082],[\"大众\",203150],[\"雪铁龙\",177298],[\"奔驰\",172238],[\"宝马\",172048],[\"奥迪\",143739]]  \n  \nfor item1,item2,item3 in zip(gem,fra,eng):  \n    print(item1[0],item1[1],\"  \",item2[0],item2[1],\"  \",item3[0],item3[1])\n",[4102],{"type":18,"tag":235,"props":4103,"children":4104},{"__ignoreMap":7},[4105,4113,4121,4129,4136,4144],{"type":18,"tag":239,"props":4106,"children":4107},{"class":241,"line":242},[4108],{"type":18,"tag":239,"props":4109,"children":4110},{},[4111],{"type":28,"value":4112},"gem=[[\"大众\",643518],[\"奔驰\",319163],[\"宝马\",265051],[\"福特\",252323],[\"雪铁龙\",227967],[\"奥迪\",255300]]  \n",{"type":18,"tag":239,"props":4114,"children":4115},{"class":241,"line":251},[4116],{"type":18,"tag":239,"props":4117,"children":4118},{},[4119],{"type":28,"value":4120},"fra=[[\"雪铁龙\", 698985],[\"雷诺\",547704],[\"大众\",259268],[\"福特\",82633],[\"宝马\",84931],[\"奔驰\",73254]]  \n",{"type":18,"tag":239,"props":4122,"children":4123},{"class":241,"line":396},[4124],{"type":18,"tag":239,"props":4125,"children":4126},{},[4127],{"type":28,"value":4128},"eng=[[\"福特\",254082],[\"大众\",203150],[\"雪铁龙\",177298],[\"奔驰\",172238],[\"宝马\",172048],[\"奥迪\",143739]]  \n",{"type":18,"tag":239,"props":4130,"children":4131},{"class":241,"line":405},[4132],{"type":18,"tag":239,"props":4133,"children":4134},{},[4135],{"type":28,"value":2476},{"type":18,"tag":239,"props":4137,"children":4138},{"class":241,"line":415},[4139],{"type":18,"tag":239,"props":4140,"children":4141},{},[4142],{"type":28,"value":4143},"for item1,item2,item3 in zip(gem,fra,eng):  \n",{"type":18,"tag":239,"props":4145,"children":4146},{"class":241,"line":424},[4147],{"type":18,"tag":239,"props":4148,"children":4149},{},[4150],{"type":28,"value":4151},"    print(item1[0],item1[1],\"  \",item2[0],item2[1],\"  \",item3[0],item3[1])\n",{"type":18,"tag":31,"props":4153,"children":4154},{},[4155],{"type":28,"value":3968},{"type":18,"tag":31,"props":4157,"children":4158},{},[4159],{"type":18,"tag":2779,"props":4160,"children":4163},{"alt":4161,"src":4162},"Pasted image 20250812101356","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250812101356.png",[],{"type":18,"tag":31,"props":4165,"children":4166},{},[4167,4169,4175,4177,4182],{"type":28,"value":4168},"如果数据中包含中文，则输出的列数据无法排列整齐。使用对齐函数",{"type":18,"tag":235,"props":4170,"children":4172},{"className":4171},[],[4173],{"type":28,"value":4174},"ljust()",{"type":28,"value":4176},"对数据进行居左对齐显示，也无法对齐数据。因为中文占据的字符长度与英文不同，此时可以使用制表符",{"type":18,"tag":235,"props":4178,"children":4180},{"className":4179},[],[4181],{"type":28,"value":3987},{"type":28,"value":4183},"来进行对齐输出。代码如下：",{"type":18,"tag":228,"props":4185,"children":4187},{"code":4186,"language":231,"meta":7,"className":232,"style":7},"gem=[[\"大众\",643518],[\"奔驰\",319163],[\"宝马\",265051],[\"福特\",252323],[\"雪铁龙\",227967],[\"奥迪\",255300]]  \nfra=[[\"雪铁龙\", 698985],[\"雷诺\",547704],[\"大众\",259268],[\"福特\",82633],[\"宝马\",84931],[\"奔驰\",73254]]  \neng=[[\"福特\",254082],[\"大众\",203150],[\"雪铁龙\",177298],[\"奔驰\",172238],[\"宝马\",172048],[\"奥迪\",143739]]  \n  \nfor item1,item2,item3 in zip(gem,fra,eng):  \n    item11 = item1[0].ljust(8)  \n    item12 = str(item1[1]).ljust(8)  \n    item21 = item2[0].ljust(8)  \n    item22 = str(item2[1]).ljust(8)  \n    item31 = item1[0].ljust(8)  \n    item32 = str(item3[1]).ljust(8)  \n    print(item11 +\"\\t\",item12+\"\\t\",\"  \",item21+\"\\t\",item22+\"\\t\",\"  \",item31+\"\\t\",item32)\n",[4188],{"type":18,"tag":235,"props":4189,"children":4190},{"__ignoreMap":7},[4191,4198,4205,4212,4219,4226,4234,4242,4250,4258,4266,4274],{"type":18,"tag":239,"props":4192,"children":4193},{"class":241,"line":242},[4194],{"type":18,"tag":239,"props":4195,"children":4196},{},[4197],{"type":28,"value":4112},{"type":18,"tag":239,"props":4199,"children":4200},{"class":241,"line":251},[4201],{"type":18,"tag":239,"props":4202,"children":4203},{},[4204],{"type":28,"value":4120},{"type":18,"tag":239,"props":4206,"children":4207},{"class":241,"line":396},[4208],{"type":18,"tag":239,"props":4209,"children":4210},{},[4211],{"type":28,"value":4128},{"type":18,"tag":239,"props":4213,"children":4214},{"class":241,"line":405},[4215],{"type":18,"tag":239,"props":4216,"children":4217},{},[4218],{"type":28,"value":2476},{"type":18,"tag":239,"props":4220,"children":4221},{"class":241,"line":415},[4222],{"type":18,"tag":239,"props":4223,"children":4224},{},[4225],{"type":28,"value":4143},{"type":18,"tag":239,"props":4227,"children":4228},{"class":241,"line":424},[4229],{"type":18,"tag":239,"props":4230,"children":4231},{},[4232],{"type":28,"value":4233},"    item11 = item1[0].ljust(8)  \n",{"type":18,"tag":239,"props":4235,"children":4236},{"class":241,"line":732},[4237],{"type":18,"tag":239,"props":4238,"children":4239},{},[4240],{"type":28,"value":4241},"    item12 = str(item1[1]).ljust(8)  \n",{"type":18,"tag":239,"props":4243,"children":4244},{"class":241,"line":1269},[4245],{"type":18,"tag":239,"props":4246,"children":4247},{},[4248],{"type":28,"value":4249},"    item21 = item2[0].ljust(8)  \n",{"type":18,"tag":239,"props":4251,"children":4252},{"class":241,"line":1444},[4253],{"type":18,"tag":239,"props":4254,"children":4255},{},[4256],{"type":28,"value":4257},"    item22 = str(item2[1]).ljust(8)  \n",{"type":18,"tag":239,"props":4259,"children":4260},{"class":241,"line":1453},[4261],{"type":18,"tag":239,"props":4262,"children":4263},{},[4264],{"type":28,"value":4265},"    item31 = item1[0].ljust(8)  \n",{"type":18,"tag":239,"props":4267,"children":4268},{"class":241,"line":1462},[4269],{"type":18,"tag":239,"props":4270,"children":4271},{},[4272],{"type":28,"value":4273},"    item32 = str(item3[1]).ljust(8)  \n",{"type":18,"tag":239,"props":4275,"children":4276},{"class":241,"line":1471},[4277],{"type":18,"tag":239,"props":4278,"children":4279},{},[4280],{"type":28,"value":4281},"    print(item11 +\"\\t\",item12+\"\\t\",\"  \",item21+\"\\t\",item22+\"\\t\",\"  \",item31+\"\\t\",item32)\n",{"type":18,"tag":31,"props":4283,"children":4284},{},[4285],{"type":28,"value":3968},{"type":18,"tag":31,"props":4287,"children":4288},{},[4289],{"type":18,"tag":2779,"props":4290,"children":4293},{"alt":4291,"src":4292},"Pasted image 20250812101529","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250812101529.png",[],{"type":18,"tag":31,"props":4295,"children":4296},{},[4297],{"type":18,"tag":35,"props":4298,"children":4299},{},[4300],{"type":28,"value":4301},"场景三：实现程序主界面",{"type":18,"tag":31,"props":4303,"children":4304},{},[4305],{"type":28,"value":4306},"利用print函数，可以输出程序界面，代码如下：",{"type":18,"tag":228,"props":4308,"children":4310},{"code":4309,"language":231,"meta":7,"className":232,"style":7},"print(\"\"\"\\033[1;35m  \n  ****************************************************************                        企业编码生成系统  \n  ****************************************************************      1.生成6位数字防伪编码 （213563型）  \n      2.生成9位系列产品数字防伪编码(879-335439型)  \n      3.生成25位混合产品序列号(B2R12-N7TE8-9IET2-FE35O-DW2K4型)  \n      4.生成含数据分析功能的防伪编码(5A61M0583D2)  \n      5.半智能防伪码自动生成(按指定样式数量自动生成)  \n      6.企业粉丝防伪码抽奖  \n      0.退出系统  \n  ================================================================  说明：通过数字键选择菜单  \n  ================================================================\\033[0m\"\"\")\n",[4311],{"type":18,"tag":235,"props":4312,"children":4313},{"__ignoreMap":7},[4314,4322,4330,4338,4346,4354,4362,4370,4378,4386,4394],{"type":18,"tag":239,"props":4315,"children":4316},{"class":241,"line":242},[4317],{"type":18,"tag":239,"props":4318,"children":4319},{},[4320],{"type":28,"value":4321},"print(\"\"\"\\033[1;35m  \n",{"type":18,"tag":239,"props":4323,"children":4324},{"class":241,"line":251},[4325],{"type":18,"tag":239,"props":4326,"children":4327},{},[4328],{"type":28,"value":4329},"  ****************************************************************                        企业编码生成系统  \n",{"type":18,"tag":239,"props":4331,"children":4332},{"class":241,"line":396},[4333],{"type":18,"tag":239,"props":4334,"children":4335},{},[4336],{"type":28,"value":4337},"  ****************************************************************      1.生成6位数字防伪编码 （213563型）  \n",{"type":18,"tag":239,"props":4339,"children":4340},{"class":241,"line":405},[4341],{"type":18,"tag":239,"props":4342,"children":4343},{},[4344],{"type":28,"value":4345},"      2.生成9位系列产品数字防伪编码(879-335439型)  \n",{"type":18,"tag":239,"props":4347,"children":4348},{"class":241,"line":415},[4349],{"type":18,"tag":239,"props":4350,"children":4351},{},[4352],{"type":28,"value":4353},"      3.生成25位混合产品序列号(B2R12-N7TE8-9IET2-FE35O-DW2K4型)  \n",{"type":18,"tag":239,"props":4355,"children":4356},{"class":241,"line":424},[4357],{"type":18,"tag":239,"props":4358,"children":4359},{},[4360],{"type":28,"value":4361},"      4.生成含数据分析功能的防伪编码(5A61M0583D2)  \n",{"type":18,"tag":239,"props":4363,"children":4364},{"class":241,"line":732},[4365],{"type":18,"tag":239,"props":4366,"children":4367},{},[4368],{"type":28,"value":4369},"      5.半智能防伪码自动生成(按指定样式数量自动生成)  \n",{"type":18,"tag":239,"props":4371,"children":4372},{"class":241,"line":1269},[4373],{"type":18,"tag":239,"props":4374,"children":4375},{},[4376],{"type":28,"value":4377},"      6.企业粉丝防伪码抽奖  \n",{"type":18,"tag":239,"props":4379,"children":4380},{"class":241,"line":1444},[4381],{"type":18,"tag":239,"props":4382,"children":4383},{},[4384],{"type":28,"value":4385},"      0.退出系统  \n",{"type":18,"tag":239,"props":4387,"children":4388},{"class":241,"line":1453},[4389],{"type":18,"tag":239,"props":4390,"children":4391},{},[4392],{"type":28,"value":4393},"  ================================================================  说明：通过数字键选择菜单  \n",{"type":18,"tag":239,"props":4395,"children":4396},{"class":241,"line":1462},[4397],{"type":18,"tag":239,"props":4398,"children":4399},{},[4400],{"type":28,"value":4401},"  ================================================================\\033[0m\"\"\")\n",{"type":18,"tag":31,"props":4403,"children":4404},{},[4405],{"type":28,"value":4406},"运行程序，将输出如图所示的程序运行主菜单。",{"type":18,"tag":31,"props":4408,"children":4409},{},[4410],{"type":18,"tag":2779,"props":4411,"children":4414},{"alt":4412,"src":4413},"Pasted image 20250812101746","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250812101746.png",[],{"type":18,"tag":31,"props":4416,"children":4417},{},[4418],{"type":18,"tag":35,"props":4419,"children":4420},{},[4421],{"type":28,"value":4422},"场景四：分行输出K3国际列车的站名",{"type":18,"tag":31,"props":4424,"children":4425},{},[4426],{"type":28,"value":4427},"如果字符串过长，希望多行显示，可以通过切片技术实现多行的输出，如下代码，设置width变量的值，即可实现对K3国际列车的站名多行输出。代码如下：",{"type":18,"tag":228,"props":4429,"children":4431},{"code":4430,"language":231,"meta":7,"className":232,"style":7},"k3='北京、张家口南、集宁南、朱日和、二连、扎门乌德、赛音山达、乔伊尔、乌兰巴托、宗哈拉、达尔汗、苏赫巴托、多卓尔内、纳乌什基、吉达、乌兰乌德、斯柳江卡、伊尔库茨克、集马、尼日涅乌丁斯克、伊兰斯卡雅、克拉斯诺亚尔斯克、马林斯克、泰加、新西伯利亚、巴拉宾斯克、鄂木斯克、伊希姆、秋明、斯维尔德洛夫斯克、彼尔姆、巴列集诺、基洛夫、高尔基、弗拉基米尔、莫斯科'  \n  \nwidth=22  \nlen1=0  \nk3line=\"\"  \nwhile len(k3)>width:  \n   k3line=k3[0:width]  \n   k3=k3[width:len(k3)]  \n   print(k3line)  \nprint(k3[0:len(k3)])\n",[4432],{"type":18,"tag":235,"props":4433,"children":4434},{"__ignoreMap":7},[4435,4443,4450,4458,4466,4474,4482,4490,4498,4506],{"type":18,"tag":239,"props":4436,"children":4437},{"class":241,"line":242},[4438],{"type":18,"tag":239,"props":4439,"children":4440},{},[4441],{"type":28,"value":4442},"k3='北京、张家口南、集宁南、朱日和、二连、扎门乌德、赛音山达、乔伊尔、乌兰巴托、宗哈拉、达尔汗、苏赫巴托、多卓尔内、纳乌什基、吉达、乌兰乌德、斯柳江卡、伊尔库茨克、集马、尼日涅乌丁斯克、伊兰斯卡雅、克拉斯诺亚尔斯克、马林斯克、泰加、新西伯利亚、巴拉宾斯克、鄂木斯克、伊希姆、秋明、斯维尔德洛夫斯克、彼尔姆、巴列集诺、基洛夫、高尔基、弗拉基米尔、莫斯科'  \n",{"type":18,"tag":239,"props":4444,"children":4445},{"class":241,"line":251},[4446],{"type":18,"tag":239,"props":4447,"children":4448},{},[4449],{"type":28,"value":2476},{"type":18,"tag":239,"props":4451,"children":4452},{"class":241,"line":396},[4453],{"type":18,"tag":239,"props":4454,"children":4455},{},[4456],{"type":28,"value":4457},"width=22  \n",{"type":18,"tag":239,"props":4459,"children":4460},{"class":241,"line":405},[4461],{"type":18,"tag":239,"props":4462,"children":4463},{},[4464],{"type":28,"value":4465},"len1=0  \n",{"type":18,"tag":239,"props":4467,"children":4468},{"class":241,"line":415},[4469],{"type":18,"tag":239,"props":4470,"children":4471},{},[4472],{"type":28,"value":4473},"k3line=\"\"  \n",{"type":18,"tag":239,"props":4475,"children":4476},{"class":241,"line":424},[4477],{"type":18,"tag":239,"props":4478,"children":4479},{},[4480],{"type":28,"value":4481},"while len(k3)>width:  \n",{"type":18,"tag":239,"props":4483,"children":4484},{"class":241,"line":732},[4485],{"type":18,"tag":239,"props":4486,"children":4487},{},[4488],{"type":28,"value":4489},"   k3line=k3[0:width]  \n",{"type":18,"tag":239,"props":4491,"children":4492},{"class":241,"line":1269},[4493],{"type":18,"tag":239,"props":4494,"children":4495},{},[4496],{"type":28,"value":4497},"   k3=k3[width:len(k3)]  \n",{"type":18,"tag":239,"props":4499,"children":4500},{"class":241,"line":1444},[4501],{"type":18,"tag":239,"props":4502,"children":4503},{},[4504],{"type":28,"value":4505},"   print(k3line)  \n",{"type":18,"tag":239,"props":4507,"children":4508},{"class":241,"line":1453},[4509],{"type":18,"tag":239,"props":4510,"children":4511},{},[4512],{"type":28,"value":4513},"print(k3[0:len(k3)])\n",{"type":18,"tag":31,"props":4515,"children":4516},{},[4517],{"type":28,"value":3579},{"type":18,"tag":31,"props":4519,"children":4520},{},[4521],{"type":18,"tag":2779,"props":4522,"children":4525},{"alt":4523,"src":4524},"Pasted image 20250812101949","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250812101949.png",[],{"type":18,"tag":4527,"props":4528,"children":4529},"style",{},[4530],{"type":28,"value":4531},"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);}",{"title":7,"searchDepth":251,"depth":251,"links":4533},[4534,4535,4536,4537,4538],{"id":25,"depth":396,"text":29},{"id":213,"depth":396,"text":216},{"id":433,"depth":396,"text":433},{"id":1003,"depth":396,"text":1003},{"id":1479,"depth":396,"text":1479},"markdown","content:blog:2025-07-02-python-语言基础.md","content","blog\u002F2025-07-02-python-语言基础.md","blog\u002F2025-07-02-python-语言基础","md",1780801018542]