Python的基础知识
来源:互联网 发布:上海乐蜀网络 编辑:程序博客网 时间:2024/05/16 23:43
数据类型
a = 1024 ; print("整数的定义",type(a))//两条语句写在一行则需要';'分割,否则不用。b = 'H' ; print("字符串的定义",type(b))c = 'Herbi' ; print("字符串的定义",type(c))d = 3.22 ; print("浮点数的定义",type(d))e = ['H','b','r','b','r'] ; print("列表的定义",type(e))f = {'Name':'Herbi',} ; print("字典的定义",type(f))g = ('Herbi',123) ; print("元组的定义",type(g))h = False ; print("布尔值的定义",type(h))
循环和判断语句
for循环
dic = {1,2,3,4,5,6,7}for i in dic: print(i)#for循环一般用来遍历列表、字典或者元组,不同于C,C++等语言中。以上语句输出列表中每一个元素。
while循环
flag = Truei = 1while flag: i += 1 if(i > 5): flag = False print('Hello world')#while后的判断语句为True才执行循环,以上程序输出5个'Hello world'
break和continue
编码
编码即将信息的一种格式转换为另外一种格式。
计算机只识别二进制数,所以需要将高级语言编译为二进制数,计算机历史上,这一编译过程遵循过多个标准。
按照其发展过程来看:(中文)
1.ASCII:只能存英文和拉丁字符,一个字符占一个字节,8位
2.gb2312:存储汉字过少
3.gbk1.0:
4.gb18030: 2000年推出,支持绝大数中文
为了解决各国各自的编码方案,推出了万国码,即Unicode。
按照其不同的编码方案,有三个分类:
1.unicode:utf-8
2.unicode:utf-16
3.unicode:utf-32
python中一般第一行声明编码方式
# -*- coding:utf-8 -*-
阅读全文
0 0
- [Python]类的基础知识
- python的一些基础知识
- Python的基础知识
- python的基础知识
- [Python]类的基础知识
- Python的基础知识
- [Python]类的基础知识
- Python的一些基础知识
- python的基础知识
- python的基础知识
- Python的一些基础知识
- selenium +python的基础知识
- python的基础知识
- Python的基础知识
- python的一些基础知识
- Python的基础知识2
- Python的一些基础知识
- python的一些基础知识
- 软件评测师资源共享
- PHP学习-1
- Spring AOP基础
- 统计一段文字中每个字符出现的次数,并输出结果(包含字符及其出现次数)保存在一个适合的集合中。
- 程序员应该学的投资
- Python的基础知识
- Tomcat启动报错 Failed to start component [StandardServer[8005]]解决
- Elasticsearch中文搜索环境搭建
- Unity Vector3.Lerp
- 单利模式
- Mybatis与Hibernate的详细对比
- HDU1856 More is better
- unique PathsII:带障碍寻径
- Maven使用tomcat8-maven-plugin插件