0-python变量及基本数据类型
2024-10-21 07:47:31
目录
1、变量
2、字符串
3、布尔类型
4、整数
5、浮点数
6、日期
1、变量
1.1、变量的定义
- 类似于标签
1.2、变量的命名规则
- (强制)变量名只能包含数字、字母、下划线
- (强制)不能以数字开头
- (强制)不能使用保留字(函数名、常量名、关键字
- (建议)尽量简短而具有描述性
- (建议)驼峰原则<大驼峰-首字母大写><小驼峰-首字母小写>
- (建议)慎用小写的l和大写的O
1.3、变量的使用
- 输出:
a = 123
print(a)
>>123
- 运算:
a = 11
b = 22
print(a + b)
>>33
- 传参
a = 3.65
abs(a)
>>3
2、字符串
2.1、用单引号括起来表示字符串(单行字符串):
str = 'this is str'
print(str)
>>'this is str'
2.2、用双引号括起来表示字符串(与单引号相同):
str =''this is str''
print(str)
>>''this is str''
2.3、用三引号括起来表示字符串(多行字符串):
str = '''this
is
str'''
print(str)
>>'''this
is
str'''
3、布尔类型
bool = True
print(bool)
>>True
bool = False
print(bool)
>>False
4、整数
a = 6
print(a)
>>6
- 转整数
a = '36'
print(a)
>>'36'
b = int(a)
print(b)
>>36
5、浮点数
a = 3.33
print(a)
>>3.33
6、日期
最新文章
- 【转载】C#怎么判断字符是不是汉字
- http协议读书笔记2-连接管理
- 【转】如何使用Android Studio把自己的Android library分发到jCenter和Maven Central
- linux内核中的GPIO系统之(2):pin control subsystem
- Unity3D ShaderLab 车辆喷漆光照模型实战
- swat主流域文件(file.cio)参数详解——引自http://blog.sciencenet.cn/blog-922140-710636.html
- ipad itunes 恢复
- css position 应用(absolute和relative用法)
- Nginx入门讲解——初步认识了解nginx.conf配置文件以及配置多个虚拟主机
- python之async-timeout模块
- 使用Bazel构建C/C++项目
- Eclipse添加git插件上传项目到github
- Atitit.pagging &#160;翻页功能解决方案专题 与 目录大纲 v3 r44.docx
- ActiveMQ任意文件写入漏洞(版本在5.12.X前CVE-2016-3088)
- [抄]使用网页进行展示而非PPT
- Tomcat------如何打开配置界面
- EJB3 jpa 数据库表的映射关系
- 转:未能打开编辑器:Unmatched braces in the pattern.
- 83. Remove Duplicates from Sorted List + 82. Remove Duplicates from Sorted List II
- python urllib2 对 http 的 get,put,post,delete