【Python编程:从入门到实践】chapter2 变量和简单数据类型
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
最新文章
- MySQL: Tree-Hierarchical query
- [转]输出带颜色的shell
- Hacker communities collection
- splay总结
- .net 大文件上传注意,修改 IIS 配置
- VMware简介
- .Net用js实现aspx页面删除TextBox输入框的前后空格
- <; meta >; 元素(转)
- Oracle 12C 简介
- Jsp页面获取项目名称
- UIScrollView 和 UICollectionView 分页效果
- poj 3522 Kruskal
- JWT实战:使用axios+PHP实现登录认证
- py文件2种执行方式
- Day9 轨道角动量
- 支持pc和移动端的手写签批功能
- 字体图标-把SVG图标转换成所需要的字体图标
- vue 组件动态 循环
- String 常用方法
- map内置函数分析所得到的思路