0 - 占位符介绍 要实现字符串的拼接,使用占位符是的一种高效.常用的方式. 举个例子,下面是不使用占位符的一种写法,直接使用加号拼接字符串 name = "Li hua" age = 24 print("Hello "+name+", you are " + str(age) + " years old") 换成使用占位符的,可以写为 name = "Li hua" age = 24 print(&quo
提到Python中的格式化输出方法,一般来说有以下两种方式: 1)% 格式说明由%和格式字符组成,如%f,%s,%d,它的作用是将数据按照指定的格式输出.格式说明是由“%”字符开始的. #1.输出字符串%s print('my name is %s' % ('xiaoming')) #2.整型输出%d print('My sister is %s, Her age is %d,'%('Lina',18)) #3.输出浮点数 print('Her height is %f m' % (1.6500
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This PEP proposes a new system for built-in string formatting operations, intended as a replacement for the existing '%' string formatting operator. 1.百分号
Python 入门之格式化输出 1.格式化 (1)%为占位 (2)%s --- 站字符串的位置(数字.字符串都能够进行填充) name = input('请输入姓名:') age = input('请输入年龄:') job = input('请输入职业:') hobby = input('请输入爱好:') msg = ''' ------------ info of Alex Li ---------- Name : %s Age : %s job : %s Hobbie: %s -------
Python基础篇(格式化输出,运算符,编码): 格式化输出: 格式:print ( " 内容%s" %(变量)) 字符类型: %s 替换字符串 %d 替换整体数字 %f替换浮点型 ------------ info of Alex Li ----------- ------------ info of %s ----------- Name : Alex Li