python上课笔记_python第一周上课学习笔记

Python第一天学习笔记

要点 1 添加作者信息

9972876aa2f3?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image

要点 2 交换变量的值

# 这是代码区域

a =1

b =2

a, b = b, a

print('a的值是:',a,'b的值是:',b)

print(type(a))

要点 3 多个变量的赋值

name, age, sex ='雷小坏',18,'m'

print(name,age,sex)

要点 4 数据类型的转换

input ('请输入')

print(type(name))

name =int(name)

print(type(name))

要点 5 判断语句(if,else)

# 判断和循环

# if else elif

# if 要判断的条件:

# 条件成立时,要做的事情

score =input('请输入您的分数')

score =int(score)

if score>=90 and score <=100:

print('考试等级是A')

elif score >=80 and score <=90:

print('考试等级是B')

elif score >=70 and score <=80:

print('考试等级是C')

elif score >=60 and score <=70:

print('考试等级是D')

else:print('成绩不及格')

要点 6 猜拳游戏

# 猜拳游戏

import random

player= input('请输入:剪刀(0),石头(1),布(2)')

player= int(player)

# 生成【0,2】随机整数

computer=random.randint(0,2)

# 获胜的情况

if (player== 0 and computer==2)or(player== 1 and computer== 0)or(player==2 and computer== 1):

print('玩家获胜')

# 平局的情况

elif (player== computer):

print('平局,要不要再来一局')

#输了

else:

print('你输了,不要走,决战到天亮')

要点 7 循环语句while

# while循环

# while 条件:

# 条件满足时执行的事情

# while True:

print('老婆我错了')

i = 0

while i < 10:

print('老婆我错了,这是我第{}次向您道歉'.format(i))

i += 1

要点 8 循环的嵌套

# *

# **

# ***

# ****

# *****

# 循环的嵌套

i = 1

while i <= 5:

j = 1

while j <= i:

print("* ",end='')

j += 1

print ('\n')

i += 1

要点 9 for循环,break和continue语句的使用

# for 循环

# for 临时变量 in 可迭代对象:

# 循环满足时要执行的事情

company= 'neusoft'

for xin company:

print (x)

if x=='s':

print("这个s要大写")

# break 立刻结束break所在的循环

# continue 结束当前循环,紧接着执行下一次循环

# break

company='neusoft'

for xin company:

print('--------')

if x== 's':

break

print(x)

else:

print('for 循环没有执行break,则执行本语句')

# continue

company='neusoft'

for xin company:

print('--------')

if x== 's':

continue

print(x)

else:

print('for 循环没有执行break,则执行本语句')

要点 10 字符串,切片

# 字符串

word= "hello , 'c'"

print(word)

# 切片:截取一部分的操作

# 对象[起始:终止:步长] 不包括结束位,左闭右开

name= 'abcdef'

print(name[4:2:-1])

print(name[3:5])

print(name[2:])

print(name[1:-1])

print(name[:])

print(name[::2])

print(name[5:1:-2])

# fedcba

print(name[::-1])

要点 11 字符串常规操作

my_str='hello world neuedu and neueducpp'

count= my_str.count('n',0,20)

print(count)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值