python基础-2 python其他知识目录

python其他知识目录

 

1、循环打印“我是小马过河”

while True:
   print('我是小马过河')

#4、用while从一打印到10

#5、请通过循环,1 2 3 4 5 6 8 9 10

#备注:连续的对其中一个不做相同的操作(连续数字指

定其中一个不打印)

#4、用while从一打印到10

#注意Python似乎不能用i++,可以i+=1 count=0 while count<10: count=count+1 print(count)

count=0
while count<10:
    count=count+1
    print(count)

count=0
while count<=9:
    count = count + 1
    print(count)

count=0
while count<10:
    count +=1
    print(count)

count=1
while count<11:
    print(count)
    count = count + 1

count=1
while count<=10:
    print(count)
    count = count + 1

#5、请通过循环,1 2 3 4 5 6 8 9 10

 #备注:连续的对其中一个不做相同的操作(连续数字指

定其中一个不打印)

count=0
while count<10:
    count=count+1
    if count != 7:
        print(count)

先打印出1-10,然后去掉7
count=0
while count<10:
    count=count+1
    if count == 7 :
        continue
    print(count)

print("""
1
3
4
5
6
8
9
10""")

count=0
while count<10:
    count=count+1
    if count == 7 :
        pass
    else:
        print(count)

6  8-10

#6、while else 结构

count=0
while count<10:
    count = count + 1
    print(count)
else:
    print("不再满足while的条件时,即whil返回值为False时执行这里,break等跳出循环的操作是否

执行else后面语句,看返回值")

#7、格式化输出

  1. %s

  2. %d

  3. %%

字符串格式化存在的意义

name = input('姓名:') do = input('在干什么:') template = "%s在教室,%s。" %(name,do,) print(template)

直接做占位符

template = "我是%s,年龄%s, 职业%s。" %("alex",73,'讲鸡汤',)

print(template)

template = "我是%s,年龄%d, 职业%s。" %("alex",73,'讲鸡汤',)

print(template)

name = 'alex'

template = "%s现在手机的电量是100%%" %(name,)

print(template)


pycharm改解释器版本

#8、打印1-100的奇数

count=0
while count<100:
    count=count+1
    if count%2 != 0:
    print(count)

#9、求和1-100

count=0
sum=0
while count<100:
    count=count+1
    sum=sum+count
    print(sum)

#10、1+2-3+4-5+6

#11、求方,

#12、求开方

#13、逻辑运算 与或非

#14、数据类型转换

bool() 数字和字符串转布尔类型,0和空字符串是False,空格是True.布尔值转换数字为0和1,转换为字

符串为字符串。 int() 字符串转数字,数字转字符串 str()

#15、value=1 or 9

#注意:似乎由此判断变量的值,然后对值进

or

"""

对于 or,如果有遇到 value= 1 or 9 第一个值如果是转换成布尔值如果是真,则value=第一值。 第一个值如果是转换成布尔值如果是假,则value=第二值。 如果有多个or条件,则从左到右依次进行上述流程。 示例: v1 = 0 or 1 v2 = 8 or 10 v3 = 0 or 9 or 8 """

and

""" 对于and,如果遇到 value= 1 and 9 这种情况 如果第一个值转换成布尔值是True,则value=第二个值。 如果第一个值转换成布尔值是False,则value=第一个值。 如果有多个and条件,则从左到右依次进行上述流程。

示例:

v1 = 1 and 9
v2 = 1 and 0
v3 = 0 and 7
v4 = 0 and ""
v5 = 1 and 0 and 9
j_str = "v1=%s v2=%s v3=%s v4=%s v5=%s" %(v1,v2,v3,v4,v5)
print(j_str)

#v1=9 v2=0 v3=0 v4=0 v5=0

行判断做对应的操作 第一个值转换布尔值如果是真,则value=第一个值 第一个值转换布尔值如果是假,则value=第二个值 如果有多个or条件,则从左到右依次

从左到右进行判断,遇到真即停止继续判断

and 遇到0就0,遇到空就空,都么遇到就是最后那个,同时遇到谁在前就是谁?

 

unicode现在基本ecs4,小表情ecs4,ecs2不包括 gbk gb2312,其中一个是另一个的升级,多一点。二者用两个字节存储汉字。 很多开源组件是国外的,用的是utf-8,建议用utf-8的编码

 
 
 
 
 

猜你喜欢

转载自www.cnblogs.com/machangwei-8/p/10617037.html