笔记出处(学习UP主视频记录) https://www.bilibili.com/video/av35698354?p=2
2.2 变量
message = "Hello Python world!" print (message)
message = "Hello Pyhton Crash Course world!" print (message)
Hello Python world!
Hello Pyhton Crash Course world!
2.2.2 使用变量时避免命名错误
message = "Hello Python Crash Course reader!" print (mesage)
print (mesage)
NameError: name 'mesage' is not defined
2.3 字符串
print ("This is a string.") print ('This is also a string.')
This is a string.
This is also a string.
2.3.1 使用方法修改字符串的大小写
name = "ada lovalace" print (name.title())
Ada Lovalace
name = "ada Lovalace" print (name.upper())
ADA LOVALACE
name = "ada Lovalace" print (name.lower())
ada lovalace
2.3.2 合并(拼接)字符串
first_name = "ada" last_name = "lovelace" full_name = first_name + " " + last_name print (full_name)
ada lovelace
first_name = "ada" last_name = "lovelace" full_name = first_name + " " + last_name print ("Hello, " + full_name.title() + "!")
Hello, Ada Lovelace!
first_name = "ada" last_name = "lovelace" full_name = first_name + " " + last_name message = "Hello, " + full_name.title() + "!" print (message)
Hello, Ada Lovelace!
2.3.3 使用制表符或换行符来添加空白
print (" Python") print ("Python")
Python
Python
print ("Language: Python C JavaScript")
Language:
Python
C
JavaScript
print ("Languages: Python C JaveScript")
Languages:
Python
C
JaveScript