七月老师python课程_七月算法课程《python爬虫》第二课: Python基础

课上记录的一些python基础应用,都是很简单的。syntax基本语法a = 1234print(a)a = 'abcd'print(a)try:print(b)except Exception as e:print(e)a = [1, 2, 3 , 4]def func(a):a[0] = 2func(a)print(a)try:# Python 2.x 支持print(100, 200, 30...
摘要由CSDN通过智能技术生成

课上记录的一些python基础应用,都是很简单的。

syntax基本语法

a = 1234

print(a)

a = 'abcd'

print(a)

try:

print(b)

except Exception as e:

print(e)

a = [1, 2, 3 , 4]

def func(a):

a[0] = 2

func(a)

print(a)

try:

# Python 2.x 支持

print(100, 200, 300)

except Exception as e:

print(e)

1234

abcd

name 'b' is not defined

[2, 2, 3, 4]

100 200 300

condition_and_loop 循环判断

score = 80

if score > 90:

print('A')

elif score > 70:

print('B')

elif score >= 60:

print('C')

else:

print('D')

total = 0

i = 1

while i <= 100:

total += i

i += 1 # 没有++i或者--i

print(total)

''' for循环只作用于容器!!! 没有这种写法: for (i = 0; i < 100; ++i): # TODO 上面这种循环只能用while实现 '''

i = 0

while i < 3:

j = 0

while j <= 3:

if j == 2:

j += 1

continue # 又去了while j <= 3

print(i, j)

j += 1

i += 1

B

5050

0 0

0 1

0 3

1 0

1 1

1 3

2 0

2 1

2 3

func函数

def hello(who = 'world'):

print('hello %s!' % (who))

hello()

hello('sea')

# f(x) = x * 5 + 100

# g(x) = x * 5; f(x) = x + 100

# => f(g(x)) = x * 5 + 100

def g(x):

return x * 5

def f(gf, x):

return gf(x) 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值