代码拉取完成,页面将自动刷新
#单引号与双引号
print( 'hell "python"' ) #hell "python"
print( "hell 'python'" ) #hell 'python'
print( "hell \"python\"" ) #hell "python"
print( 'hell \'python\'' ) #hell 'python'
#三引号 空行也会输出
print('''
hello
ok
''')
print("====")
print("""
hello
ok
""")
#字符串中使用变量
x=123
print("x=", x) #x= 123
print(f"x={x}") #x=123 嵌入值
print(f"{x} {x} twice") #123 123 twice
y=456
print(f"{x} {y} two numbers") #123 456 two numbers
#字符基本操作
print("x" in "x123") #True
print("x" not in "x123") #False
print("abc"+"def") #abcdef
print("abc"*3) #abcabcabc
#切片
print("abcdef"[3]) #d
print("abcdef"[-1]) #f
print("abcdef"[1:4]) #bc
print("abcdef"[1:]) #bcdef
print("abcdef"[1:5:2]) #bd 从1到5,步长为2
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。