liuxiaoyun111 发表于 2018-8-15 13:13:13

【一】初识Python要点总结

  python
  1.GIL   全局解释锁 (只能用一个核,线程受损,所有比较不好)
  2.强类型      比如,不会想加不同类型的指定,会直接报错。
  3.面向对象
  4.函数式
  多进程方式提升速度,解决单核。
  #list 链表
  L=
  添加函数: L.append(5) [向后添加]
  求长度函数: len()
  #for
  for x in :
  print x
  常见错误:索进错误
  #range
  print range(0,10)
  #if
  if True:
  print 'x'
  if a =='1' and b=='2':
  print 'xxx'
  else:
  print 'b'
  #help
  help(str)
  #tuple(元组)[不可变]
  ("A","B")
  #string str [不可变]
  #dict,键值对,key-value
  d={
  "a":"abc",
  'b':123,
  'c':
  'd':{'a':111}
  }
  print d['a']
  #file
  with(上下文管理文件)
  with open('my_test.txt','r')as f:
  text=f.read()
  print text
  out="""1,2,3,4"""
  with open('my_test.txt','r')as f:
  f.write(out)
  #布尔类型
  True
  False   '',0,None,[],{}
  a=[]
  if a:
  print 'a',a
  else:
  print 'empty'
  if a is None:         【用is判定】
  print 'None'
  #input
  a=input("input a number:")
  print type(a),a
  #猜数游戏
  1 import random
  2 x=random.randint(0,20)
  3 print "\n------Find a number in0-20------\n"
  4 for i in range(0,3):
  5    a=input("input the number:")
  6    if a < x:
  7         print "small"
  8    elif a > x:
  9         print "big"
  10    else:
  11         print "Right"
  12         print " 1 yuan"
  13         break
  14 print "\nThe numberis",x
页: [1]
查看完整版本: 【一】初识Python要点总结