Python字符串操作

#coding=utf-8
#轉義字符
#\n -回車
#\' -'號
#\" -雙引號
#\t -製表符
#\\ -\斜槓
print("Hello there !\nHow are you?\nI\'m doing fine。\n\"My name is wangyongke.\"")
print("\t Hello,I\'m here.")
print("Hello,this is \\.")


#原始字符串 --打印所有的字符不進行轉義
print(r"Hello there!\nHow are you!")
print(r'Hello,\n \t \\ \'\"')


#三重引號  3個單引號或者雙引號
#\\ 在三重引號中也轉義
print('''
Hello, there!
 How are you?
    I'm doing fine.
    \\\\\\\\\\\\
''')
#三重引號作爲多行註釋如下
'''
eg:
print('Hello')
'''





#字符串下標和切片
str01='wang yongke'
print(str01[0:4])
print(len(str01))
j=0
for i in str01:
    print(i,end="")
    print(j,end="")
    j+=1


#字符in and not in 操作
print('\n')
print('w' in str01)
print('gg' not in str01)



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章