一、print输出
常量直接输出:除了整形其它都需要添加单双引号 print('kx献爱心')、print(123)、print('1'+'2')
变量间接输出:不需要添加引号 a='hello' print(a)、print(type(a))
# 单、双、三都不能包含自己本身
# 单引号中可以包含双引号,不能包含单引号和三引号
# 双引号中可以包含单引号和三引号,不能包含双引号
# 三引号中可以包含单引号好爽引号,不能包含三引号
二、print之格式化输出
%s、%c、%d和%i、%o、%x、%f、%%
a = 'hello' >> print('%s暗属性'%a)
a = 's' >> print('%c长十九'%a)
a = 12 >> print('%d is ok'%a)
a = 12 >> print('%f is ok'%a)
a = 12 >> print('%d%%的爱'%a)
三、python中的命名规则
第一个字符必须是字母表中字母或下划线 _,标识符的其他的部分由字母、数字和下划线组成,标识符对大小写敏感
四、python中的输入
输入语句:input() eg: name = input('请输入您的姓名:')
username = input('请输入id:')
if username == 'admin':
password = input('请输入密码:')
if password == '123456':
yzm = input('请输入验证码:')
if yzm == '123':
print('输入正确')
else:
print('验证码输入错误')
else:
print('密码输入错误')
else:
print('id输入错误')
五、运算符
算数运算符:+、-、*、/、%、**(取幂)、//(取商)
赋值运算符:=、+=、-=、*=、/=、%=、**=、//=
比较运算符:==、!=、>、<、>=、<= print(a>b) 返回 False/True
逻辑运算符:
and与 print(a>c and a<c) 返回 False、True
or或 print(a>c or a>b) 返回 False、True
not非 print(not(a>c)) 返回 False、True
位运算:
&按位与 a=5 b=6 print(a&b) 返回 4 (二进制操作,位中有0为0)
| 按位或 a=5 b=3 print(a|b) 返回 7 (二进制操作,位中有1为1)
^按位异 a=5 b=3 print(a^b) 返回 6 (二进制操作,位中异为1,同为0)
~按位取反 a=5 print(~a) 返回 -6 (二进制操作,~x=-(x+1) )
<<左移 a=5 c=3 print(a<<3) 返回 40 (二进制操作,左移右添0)
>>右移 a=5 c=1 print(a>>3) 返回 2 (二进制操作,右移左添0)
成员运算符:
in:a=5 list=[1,2,3,4,5] if(a in list): print('存在') print(1 in list) 返回 True
not in:b=10 list=[1,2,3,4,5] if(b not in list): print('不存在') print(1 not in list) 返回 False
|
|