10 月 262020
 
# 变量名只能包含字母,数字和下划线
# 变量名能以字母和下划线开头,但不能以数字开头
# 变量名不能包含空格

# 使用字符串的.title()方法修改大小写
name = 'harvey mei'
print(name.title())  # 该方法以首字母大写的方式显示每个单词

# 将字符串全部改为大写或小写
name = 'Ada Lovelace'
print(name.upper())  # 大写
print(name.lower())  # 小写

# 在字符串中使用变量
first_name = 'tom'
last_name = 'chen'
full_name = f"{first_name} {last_name}"  # f字符串在python3.6引入
print(full_name)

first_name = 'alice'
last_name = 'wang'
full_name = "{} {}".format(first_name, last_name)  # 使用python3.5或更早版本需要使用format()方法
print(full_name)
D:\PycharmProjects\pythonProject2\venv\Scripts\python.exe D:/PycharmProjects/pythonProject2/hello1.py
Harvey Mei
ADA LOVELACE
ada lovelace
tom chen
alice wang

Process finished with exit code 0

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)