程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

python入门基础 02

发布于2019-08-08 09:55     阅读(782)     评论(0)     点赞(5)     收藏(3)


1.while

# while -- 关键字 (死循环)
#
# if 条件:
#     结果
#
# while 条件:
#     循环体

# print(1)
# while True:
#     print("痒")
#     print("鸡你太美")
#     print("卡路里")
#     print("好运来")
#     print("小三")
#     print("小白脸")
#     print("趁早")
#     print("过火")
# print(2)

# falg = True
# while falg:
#     print(1)
# print(2)



# print(bool(0))
# 数字中非零的都是True


# 正序的示范
# count = 1
# while count <= 5:
#     print(count)
#     count = count + 1


# 倒序的示范
# count = 5
# while count:
#     print(count)
#     count = count - 1


# 正序打印从 25 - 57
# count = 25
# while count <= 57:
#     print(count)
#     count = count + 1


# 倒序打印从 57 - 25
# count = 57
# while count >= 25:
#     print(count)
#     count = count - 1

# break
# continue

# while True:
#     print(123)
#     print(234)
#     break   # 终止当前循环,break下方的代码不会进行执行
#     print(345)
# print(1111)

# while True:
#     print(123)
#     print(234)
#     print(345)

# while True:
#     print(123)
#     print(234)
#     continue
#     #continue 伪装成循环体中的最后一行代码(跳出当前循环继续下次循环)
#     #continue 下面的代码不会执行
#     print(345)
# print(1111)

# while else

# while True:
#     print(111)
#     break
# else:
#     print(222)

# while True:
#     print(111)
#     break
# print(222)



# 总结:
    # 打断循环的方式:
    #     1.自己修改条件
    #     2.break
    # break -- 打破当前循环 (终止当前循环)
    # continue -- 跳出当前循环继续下次循环(将continue伪装成循环体中的最后一个行代码)
    # break和continue相同之处:他们以下的代码都不执行

2.字符串格式化

# a = "------------- info -------------"
# b = "name:"
# c = "age:"
# d = "job:"
# e = "-------------- end -------------"
# name = input("name")
# age = input("age")
# job = input("job")
# print(a + "\n" + b + name + "\n" + c + age + "\n"+ d + job + "\n" +e)

# s = """ ------------- info -------------
# name:%s
# age:%s
# job:%s
# -------------- end -------------
# """
# name = input("name")
# age = int(input("age"))
# job = input("job")
# print(s%(name,age,job))

# num = input('学习进度:')
# s11 = "大哥黑的学习进度为:%s %%"
# print(s11%(num))

# s = f"今天下雨了{input('>>>')}"
# print(s)

# s11 = "大哥黑的学习进度为:%s"
# print(s11%("不错"))

# s = f"{1}{2}{3}"
# print(s)


# %s 是占的字符串类型的位置
# %d 是占的数字类型的位置
# %% 转换成普通的%号
# 按照位置顺序传递,占位和补位必须要一一对应

3.运算符

算数运算符
+
-
*
/
//(整除-地板除)
**幂(次方)
% 模 (取余)
print(5 % 2)


比较运算符
#>
<
==  (等于)
!= (不等于)
#>=
<=


赋值运算符
    =  赋值
    += 自加
a = 10
a += 1
print(a)  #a=a+1
    -=
    *=
    /=
    //=
    **=
    %=

逻辑运算符
and (与/和)
#or (或)
not (非)

print(3 and 4)
print(0 and 4)
print(0 and False)

and 都为真的时候取后值
and 都为假的时候取前值
and 一真一假取假的

print(3 and 5 and 9 and 0 and False)
print(5 and False and 9 and 0)
print(1 and 2 and 5 and 9 and 6)

or 都为真的时候取前值
or 都为假的时候取后值
or  一真一假取真的

print(1 or 0)
print(1 or 2)
print(0 or False)

print(not False)   #相反

() > not > and > or
从左向右执行
print(9 and 1 or not False and 8 or 0 and 7 and False)

成员运算符

in 存在
not in 不存在

s = "xcs"
if "sb" not in s:
    print(True)
else:
    print(False)

4.编码初始

01010110001000011001
便 100001001111


00000101  00000110  0010000110011001

ascii (老美)不支持中文
gbk    (国标) 英文 8位  中文16位
unicode (万国码)英文16 位 中文 32位
utf-8   (可变长的编码) 英文8位 欧洲文 16位 亚洲24位


linux -- utf-8
mac -- utf-8
windows -- gbk

单位转换:
1字节 = 81Bytes = 8bit ***
1024Bytes = 1KB
1024KB = 1MB
1024MB = 1GB
1024GB = 1TB  *** TB就够用了
1024TB = 1PB
1024PB = 1EB
1024EB = 1ZB
1024ZB = 1YB
1024YB = 1NB
1024NB = 1DB

总结

""""
1.while循环 -- 死循环
while 条件:
    循环体

打断死循环:
    break  -- 终止当前循环
    改变条件 -- 自动定义修改控制执行次数

关键字:
    break  -- 终止当前循环
    continue -- 伪装成循环体中最后一行代码(官方:跳出本次循环,继续下次循环)
while else:while条件成立的时候就不执行了,条件不成立的时候就执行else



2.字符串格式化:
    %  -- 占位
    %s -- 占字符串的位
    %d -- 占数字位
    %% -- 转义成普通的%
    s = "你好%s"
    s%("我好")

    f"{变量名}{字符串}" 3.6版本及以上才能使用


3.运算符
    算数运算符 : + - * / // ** %
    比较运算符: > < >= <= == !=
    赋值运算符: = += -= *= /= //= **= %=
    逻辑运算符: and or not () > not > and > or
    成员运算符: in not in

4.编码:
    编码集(密码本)
    ascii:
        不支持中文
    gbk:
        英文 8位  1字节
        中文 16位 2字节
    unicode:
        英文 16位 2字节
        中文 32位 4字节
    utf-8:
        英文 8 位 1字节
        欧洲 16位 2字节
        亚洲 24位 3字节

    # 单位转换:
    # 1字节 = 8位
    # 1Bytes = 8bit ***
    # 1024Bytes = 1KB
    # 1024KB = 1MB
    # 1024MB = 1GB
    # 1024GB = 1TB  *** TB就够用了
    # 1024TB = 1PB
    # 1024PB = 1EB

"""


所属网站分类: 技术文章 > 博客

作者:我好看吗

链接:https://www.pythonheidong.com/blog/article/12817/1a996c30c9de7cb16aaa/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

5 0
收藏该文
已收藏

评论内容:(最多支持255个字符)