Python
临江仙我亦是行人
纸上得来终觉浅,绝知此事要躬行
展开
-
Python格式化之format()格式化
利用format()方法实现字符串格式化%占位符的方式要刻意区分变量类型,format()方法则无需考虑变量类型>>> a = 'teacher'>>> b = 92.3675>>> print('hello {0}, your score is {1}, good luck for {0}'.format(a,b))hello teacher, your score is 92.3675, good luck for teacher>原创 2021-04-10 10:28:53 · 221 阅读 · 0 评论 -
Python格式化之f_string格式化
利用f_string实现字符串格式化(python3.6之后的版本新增)在字符串的前面加上f前缀,并将变量名称用大括号括起来,Python就可以自动识别并引用变量#其他前缀>>> b'hello'b'hello'>>> bytes<class 'bytes'>>>> r'c:\windows\files''c:\\windows\\files'>>> r'/etc/passwd''/etc/passwd原创 2021-04-10 10:27:57 · 165 阅读 · 0 评论 -
Python格式化之%占位符格式化
%占位符字符串格式化:在要引用变量的位置使用一个占位符来代替,最后在字符串的后面再按顺序指定这些变量的名称# 格式print "String %format1 %format2 ....." %(variable1,variable2,.......)#>>> name = "teacher">>> week = "Sunday">>> print("hello %s, today is %s" % (name,week))hello t原创 2021-04-10 10:27:01 · 438 阅读 · 0 评论 -
Python字符串格式化
1. 什么是字符串格式化将其他类型的数据转换为字符串,或在字符串中引用一些变量,就要用到字符串格式化>>> a = 2>>> b = a + 3>>> b5#>>> a="teacher">>> b="hello a">>> b'hello a'>>> 显然可以采用字符串和变量拼接的方法,但如果要引用的变量数目比较多,就是显得非常复杂>>>原创 2021-04-10 10:26:00 · 63 阅读 · 0 评论 -
python字符串对象介绍
1.介绍在Python中,凡是用引号引起来的全是字符串字符串str,定义字符串可以使用单引号(推荐)或双引号,字符串有多行时可以使用三对单/双引号(’’’ , “”"),表示多行内容>>> s = ''' welcome... to ... beijing... '''>>> print(s) welcome to beijing>>> 在安全和运维工作中所要处理的数据类型主要是字符串每个原创 2021-04-10 10:23:39 · 473 阅读 · 1 评论