Python 知识点整理

一.

from os import makedirs, unlink, sep   #从os包中引入 makedirs.unlink,sep类

from os.path import dirname, exists, isdir, splitext  #从 os包中的path类中引入 dirmame exists 等方法

import os #引入整个os包

import os as o #为os起别名为o

二.

a[1: ] 表示该列表中的第1个元素到最后一个元素,而,a[ : n]表示从第0歌元素到第n个元素(不包括n)


注释:#

多行注释:'''          ''''

a=2

a*2

a**2

a, b, c=2, 3, 4

s='I like python'

s+'very much'

s.split(' ')   #将s以空格分开,得到列表['I', 'like', 'python']


if, for, while操作:

if 条件1:

    语句1

elif 条件2:

    语句2

else:

    语句3


s, k=0

while k<100:

    k=k+1

    s=s+k

print s


s=0

for s in range(101):

    s=s+k

print s

range(4) : 0, 1, 2, 3

range(1, 4, 1) : 1, 2, 3


函数

def add2(x):

    return x+2

print add(1)


def add2(x, y)

    return x+3, y+3

a, b=add2(1, 2)


f = lambda x : x + 2   #使用lambda定义行内函数f(x)=x+2

g = lambda x , y : x + y   #使用lambda定义行内函数g(x,y)=x+y

 

python写

with open(路径, 'w') as fr:
    fr.write("I\tlove\nprogramming\t.\n")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值