Python one day

1.常量定义必须全部大写
2.Python2.x中文必须声明UTF-8

#!_*_ coding:utf-8 _*_
#coding:utf-8
3.input()接受的所有数据都默认处理成字符串
a==b 判断
a!= 不等同
a>=b 大于等于
a<=小于等于

and or not 逻辑运算符{短路原则}
while 条件:
       **************************
break continue

print("hello",end="")

··· 
···多行注释 and 多行打印

占位符:
%s string

if salary.isdigit():
    salary = int(salary)
else:
    print("you input digit")
判断salary是不是数字

字符格式化输出
占位符:
%s s=string
%d d=digit 整数
%f f=float 浮点数
数据运算:
数据初始类型
数字:
整数 int(integer)
整型
长整型( in PY3 不区分了)
range(起,末,步长)
前闭后开

for循环:
for i in range(3):
    print("look",i)
结果:
look 0
look 1
look 2

列:多次登陆与判断

_username = "bibi"
_password = "admin"
denglyanz = False
for i in range(3):
    username = input("UserNmae:")
    password = input("PsaaWorld:")
    if username == _username and password == _password :
        print("Welcome to %s !"%username)
        denglyanz = True
        break
    else:
        print("You input UserName or PassWorld NO!")
if denglyanz == False :
    exit("你在暴力破解吗FUCK")

解发二:

_username = "bibi"
_password = "admin"
for i in range(3):
    username = input("UserNmae:")
    password = input("PsaaWorld:")
    if username == _username and password == _password :
        print("Welcome to %s !"%username)
        break
    else:
        print("You input UserName or PassWorld NO!")
else:
    exit("你在暴力破解吗FUCK")

解法3:

_username = "bibi"
_password = "admin"
jsq= 0
while jsq<3:
   username = input("UserNmae:")
   password = input("PsaaWorld:")
   if username == _username and password == _password:
       print("Welcome to %s !" % username)
       break
   else:
       print("You input UserName or PassWorld NO!")
   jsq += 1
else:
   exit("你在暴力破解吗FUCK")

注意标志位的用处
<h1>列表and元祖</h1>
List列表[]
name = ["one","two","sadju","asads"]
增 删 改 查
1.查
name[2]

增 切片:
name[2:4] -> ['sadju', 'asads'] #前闭后开

one
步长

步长和方向
增加:
append or insert
append加入会把值放在最后一个里面
inset会插入到你要插入的地方(更加灵活)

append
insert

修改:

修改
多修改

删除:
remove pop del

remove
pop
pop
del

列表内置方法:
1.count
统计某个元素在列表中出现的次数

count

2.extend {延伸}方法在列表的末尾一次性追加的另一个序列中多个值

extend

3.index方法
查找参数的位置
{以第一个为主}


index
index多个

4.reverser{反向器}方法

reverser

排序
数字排序.sort()方法

sort
重大到小

小总结:
查:
.count 查某个元素出现次数
.index 根据内容查位置
增加:
a.append() 追加都最后
a.insert(index,"内容")
a.extend 扩展
修改:
a.[index] = "新值"
a[start:end] = [a,b,c] 修改多个地方
删除:
a.remove("内容")
a.pop("下表") 没有指定下表会删最后一个
a.clear() 清空
排序:
sort()
reverse()
身份运算
type(a) is list

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容