python初识(2)

1 字符串格式占位符

1.1%s %d %% 占位符

预留 字符串 整型 (转义)

name = input('name:')
print ('你的名字是:%s'%(name))

1.2 f""

name = input('name:')
print (f"你的名字是{name}")

1.3 formit()

name = input()
age = input()
print ('你的名字是{0},年龄{1}'.formit(name,age))

实际上是元组传递,所以有01索引,也可以使用关键字占位

2 while 循环

while 条件:
	循环体
else:
	代码块

while循环两种终止循环的方式

​ 1 循环条件为False

​ 2 循环体中执行到break

continue关键字:跳出本次循环,开始下一次,当continue为循环体最后一层

else:当while循环体正常结束(非break)时,执行else里的内容

break关键字执行时else不执行 因为else属于while循环的一部分

3 编码

走向

ascii(英1) -- Unicode(英2中4) -- utf-8(英1 欧2 中3)

1 B == 8 b

4 运算符

1.1赋值运算符

= += -= *= /=

1.2算术运算符

**+ - * / // % ** **

1.3 逻辑运算符

**and (与)or(或)not(非) **

and 两者皆真才为真(运行到底)

or 一者为真就为真(运行到真)

1.4 身份运算符

in not in

1.5 比较运算符

> < >= <= !=

原文地址:https://www.cnblogs.com/albert0823/p/10974016.html