长风破浪会有时,直挂云帆济沧海

Dream Word

博客园 首页 新随笔 联系 订阅 管理

2.1 运行
2.2 变量
message = "hello"
print(message)
2.2.1 变量的命名和使用
2.2.2 使用变量是避免命名错误
2.3 字符串
“Hello”
‘Hello’
“Hello ‘zhaohu’”
'this is "dog"! '

2.3.1 使用方法修改字符串的大小写
name = "My name is zhao"
print(name.title())
name.upper()
name.lower()

2.3.2 合并(拼接)字符串
first_name = "zhaohu"
last_name = "hu"
full_name = first_name + " "+last_name
print(full_name)

2.3.3 使用制表符或换行符来添加空白
\t \n

2.3.4 删除空白
rstrip();确保字符串末尾没有空格

2.3.5 使用字符串时避免语法错误

message = "One of Python's strengths is its diverse community"
print(mssage)
此处的字符串只能使用双引号。

2.4 数字
2.4.1 整数
+ - * / **(乘方)

2.4.2 浮点数

2.4.3 使用函数str()避免类型错误
age = 23
message = "Happy" + str(age) + "rd Birthday"
print(message)

2.4.4 Python 2中的整数
3.0/2 = 1.5 3/2 = 1 (Python3: 3/2=1.5)

2.5 注释
2.5.1 如何编写注释
# This is note

 

posted on 2017-12-16 21:54  长风II  阅读(149)  评论(0编辑  收藏  举报