python学习笔记——week_1

第一章 Python基础

1.操作符

操作符操作示例
**指数运算2**3=8
%取余数22%8=6
//取整22//8=2
==是否相等42==42.0 >>True

2.字符型变量运算

情形示例结果
字符型变量相加‘girl’+‘friend’girlfriend
字符型变量乘整型变量‘boy’*3‘boyboyboy’

3.函数小结

函数作用
print()显示字符串
input()回车之前输入的文本保存为字符型变量
len()计算字符型变量的长度,并保存为整型变量
str()、int()、float()转换为字符型整型浮点型变量
round()四舍五入到指定精度
abs()取绝对值

第二章 控制流

1.布尔值

True和False:做变量值时只能大写,且不能作为变量名

2.布尔操作符

操作符含义
and
or
not

运行优先级:not > and > or

3.if和elif条件句实践

用户登录板块:

print('welcome to here')
print('Are you Jack or Mary?')
name =input()
print('Please enter your password')
password =input()
if name =='Mary':
    print('HEllo Mary')
    if password == 'swordfish':
        print('Access granted')
    else:
        print('Wrong password')
elif name =='Jack':
    print('HEllo Jack')
    if password == 'tortoise':
        print('Access granted')
    else:
        print('Wrong password')
else:
    print('user name does not exist')

4.while 和 break语句

无限循环:

while True:
    print('plase enter your name')

break解除循环:

while True:
    print('plase enter your name')
    name=input()
    if name =='your name':
        break
print('thanks')

continue无解继续循环:

while True:
    print('plase enter your name')
    name=input()
    if name !='your name':
        continue
print('thanks')

5.for循环和range()函数

range(a,b,c):设定范围
a表示起始值,默认为0;
b表示结束值,不可省略;
c表示步长,默认为1。
range(0,10,2) 表示取值为(0,2,4,6,8)

for循环语句(打印1-5)

for i in range(5):
    print(str(i))

等价while循环

i=0
while i<5:
    print(str(i))
    i=i+1

6.模块导入

导入方式调用模块函数(以random模块为例)
import randomrandom.randint()
from random importrandint()

此外,在模块sys中sys.exit()函数可以强制退出循环

注:小于等于为<=

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值