Python入门基础(第二天):基本运算符

一、运算符 

1、算数运算符

2、比较运算符

3、逻辑运算符

4、赋值运算符

5、成员运算符

6、while循环

a=input("number:")
b=input("number:")
print(int(a)+int(b))
print(type(a))
content=input("请输入数字:")
if content == '1':
    print("你好啊!")
else:
    print("hello world")
number=88
content = int(input("请输入数字:"))#默认字符串,需要强制转换
if content > number :
    print("你太大了!")
elif content < number :
    print("你太小了!")
else:
    print("恭喜你猜中了!")
#whlie循环
#1.continue和break两者的用法
while True:
    content=input("请输入一句话,(按q可以退出循环!):")
    if content=='q':
        continue
        #break
    print(content)
#2.输出1-10之间的所有数,除4以外
count=1
while count <=10:
    if count==4:
        count = count + 1
        continue
    print(count)
    count=count+1

7、格式输出

# %s  占位符,占位字符串
# %d  占位符,占位数字
name="华少年"
age='22'
hobby="看书、运动"
location="家里"
print("一个叫"+name+""+age+"岁年轻小伙,喜欢在"+location+hobby+"")
print("一个叫%s的%s岁年轻小伙,喜欢在%s哦" %(name,age,hobby))

8、运算符

 

# **次幂
# % 余数
# // 整除
# / 普通除
# and 表示并且
# or  表示或者
# not 非真既假,非假既真,表取反
#优先级:()>  not  >  and  >  or
#x or y:如果x为0,返回y;如果x为非零,返回x;例:1 ro 2结果为1;0 or 2 结果为2
#x and y,与 or 相反。0 and 任何数为0;非零 and 非零任意数为大后者。

 

9、编码

# ASCll码: 8位,1字节
# GBK码: 16位,2字节
# UNICODE码: 32位,4字节
#UTF-8: 可变长编码
    #英文:8位
    #欧文:16位
    #汉字:24位
posted @ 2018-12-31 21:34  全村的希望、  阅读(227)  评论(0编辑  收藏  举报