CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day12/str1.py
Views: 729
1
"""
2
字符串常用操作
3
4
Version: 0.1
5
Author: 骆昊
6
Date: 2018-03-19
7
"""
8
9
import pyperclip
10
11
# 转义字符
12
print('My brother\'s name is \'007\'')
13
# 原始字符串
14
print(r'My brother\'s name is \'007\'')
15
16
str = 'hello123world'
17
print('he' in str)
18
print('her' in str)
19
# 字符串是否只包含字母
20
print(str.isalpha())
21
# 字符串是否只包含字母和数字
22
print(str.isalnum())
23
# 字符串是否只包含数字
24
print(str.isdecimal())
25
26
print(str[0:5].isalpha())
27
print(str[5:8].isdecimal())
28
29
list = ['床前明月光', '疑是地上霜', '举头望明月', '低头思故乡']
30
print('-'.join(list))
31
sentence = 'You go your way I will go mine'
32
words_list = sentence.split()
33
print(words_list)
34
email = ' [email protected] '
35
print(email)
36
print(email.strip())
37
print(email.lstrip())
38
39
# 将文本放入系统剪切板中
40
pyperclip.copy('老虎不发猫你当我病危呀')
41
# 从系统剪切板获得文本
42
# print(pyperclip.paste())
43
44