1,使用while循环输出1,2,3,4,5,6,8,9
# 使用while循环输出1,2,3,4,5,6,8,9 num = 1 while num <= 10: if num != 7: print (num ) num += 1 num = 1 while num < 10: num +=1 if num ==7: continue print(num) num = 1 while num < 10: num +=1 if num ==7: pass else: print(num)
2,输出0-100内所有奇数的和
#输出0-100内所有奇数 num = 1 sum = 0 while num <=100: if num%2 !=0: sum +=num num +=1 print(sum) num = 1 sum = 0 while num <=100: sum +=num num +=2 print(sum)
3,print long messge 注意变量类型,个数要对应的上,不然会报错
""" Version : 0.1 Author : Lisa Date : 2018/11/25 8:02 AM Description : """ msg ='''--------------info of lisa------------ name:lisa age:22 job:developer Hobbies:piano,yoga ------------------end-----------------------''' print(msg) --------------info of lisa------------ name:lisa age:22 job:developer Hobbies:piano,yoga ------------------end-----------------------
""" Version : 0.1 Author : Lisa Date : 2018/11/25 8:02 AM Description : """ age = int(input("please input your age:")) name =input("please input your name:") height=int(input("please input you height:")) msg="my name is %s, i am %d, my height is %d" %(name,age,height) print(msg) please input your age:22 please input your name:lisa please input you height:165 my name is lisa, i am 22, my height is 165
4,如果字符串里面已经有了单引号的三引号,那么外面要用栓双引号的三引号,不然会报错
5,字符串里面打印%
sg="my name is %s, i am %d, my height is %d,学习进度3%" %(name,age,height) print(msg) 注意观察,这样写的话, pycharm字符串会标黄,提示语法有问题 运行结果 please input your age:22 please input your name:lisa please input you height:165 Traceback (most recent call last): File "/Users/guolixiao/PycharmProjects/lisa's_practise/boys/2.1.py", line 12, in <module> msg="my name is %s, i am %d, my height is %d,学习进度3%" %(name,age,height) ValueError: incomplete format 正确写法,应用%来转义 msg="my name is %s, i am %d, my height is %d,学习进度3%%" %(name,age,height) print(msg) 运行结果: please input your age:22 please input your name:lisa please input you height:165 my name is lisa, i am 22, my height is 165,学习进度3% 输出%d msg="my name is %s, i am %d, my height is %d,学习进度3%%d" %(name,age,height) print(msg) 运行结果: my name is lucy, i am 22, my height is 167,学习进度3%d
6,while else,只要while循环不被break跳出,else部分就会被执行
7,电脑的传输还有储存实际上都是0101010这种的,电脑的成千上万的二极管等设备可以实现高地电平
8,美国发明了ASCII码,由于英文字符加符号很少,所以一开始就设计了7位 可以储存128个字符,发明者还是有先见的,多用了一个第8位以防字符不够用,但是虽然这样,还是明显不够用,ASCII码最左边一位永远是0,中文汉字有9万多个,美国为了解决全球化的文字问题,发明了一个万国码也就是Unicode,一开始给了中文两个字节,但是只可以储存65535个字,明显不够用,后来给了四字节,但是又太多了,会造成很多浪费,中文3个字节足以,所以后来有了一个升级版本的万国码就是UTF-8,使用3个字节储存中文,一个字节表示英文,两个字节其他,GBK是中国人发明的,用两个字节表示一个汉字,只在国内用。