python示例程序整理

发布时间 2023-07-08 00:12:30作者: ganwong99

来自于《python编程:从入门到实践》

变量和简单数据类型

print("Hello Python world!") #hello world bring me luck
message = 'hello world!'
print(message)

字符串

name = "Ada Lovelace"
print(name.title()) #方法是Python可对数据执行的操作。方法.title()将每个单词的首字母都改为大写
print(name.upper()) #字符串改为全部大写
print(name.lower()) #字符串改为全部小写
first_name = "ada"
last_name = "lovelace"
full_name = first_name + " " + last_name
message = "Hello, " + full_name.title() + "!" #用 + 拼接字符串
print(message)