Python要点学习

Python学习要点:

1、基本数据类型

2、如何自定义数据结构

3、if  for  while 语句

4、系统调用如何使用

5、多线程如何操作


一、python数据类型

1.1、字符串

a、使用单引号(')
用单引号括起来表示字符串,例如:
str='this is string';
print str;

b、使用双引号(")
双引号中的字符串与单引号中的字符串用法完全相同,例如:
str="this is string";
print str;

c、使用三引号(''')
利用三引号,表示多行的字符串,可以在三引号中自由的使用单引号和双引号,例如:
str='''this is string
this is pythod string
this is string'''
print str;

1.2、布尔类型
bool=False;
print bool;
bool=True;
print bool;

1.3、整数
int=20;
print int;

1.4、浮点数
float=2.3;
print float;

1.5列表

list=['physics', 'chemistry', 1997, 2000];
nums=[1, 3, 5, 7, 8, 13, 20];

1.5.1 遍历列表

for  element  in list:

print element

1.5.2获得列表长度

nlen = len(list)

1.5.3自动生成数字列表

numList = range(len(list))

print numList

结果:[0,1,2,3]


1.6元组

Python的元组与列表类似,不同之处在于元组的元素不能修改;元组使用小括号(),列表使用方括号[];元组创建很简单,只需要在括号中添加元素,并使用逗号(,)隔开即可,例如:

tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5 );
tup3 = "a", "b", "c", "d";
1.7字典

字典(dictionary)是除列表之外python中最灵活的内置数据结构类型。列表是有序的对象结合,字典是无序的对象集合。两者之间的区别在于:字典当中的元素是通过键来存取的,而不是通过偏移存取。

dict = {'Alice': '2341', 'Beth': '9102', 'Cecil': '3258'};

1.8文件操作
例子:

f = open(fileName, "r")
while True:

line = f.readline()
  if line:
  if len(line) > 2:
  print line
  filelist.append(line)
else:
print "null..........."
  else:
break

打开文件:f = open(filename, flag)

读取行:   line = f.readline() 读取完毕收,返回空




5、如何自定义数据结构
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值