| 编写好代码,再保存代码,F5运行 |
|
| Python 语法简洁的可交互的高级语言 |
10.80.74.11:8001/ |
| print语句 |
|
| print(5//3) |
1 |
| print(5/3) |
1.66666...667 |
| print(2**5) |
32 |
| print(3**0.5) |
1.732... |
| print(5%3) |
2 |
| print("hello") |
hello |
| print('hello') |
单引号括住的也是字符串 |
| print('he says,"ok"') |
he says,"ok" |
| print(1,2,3) |
1 2 3 |
| print("a",20,"cd") |
a 20 cd |
| print(20,'u',30,**sep='+'**) |
20+u+30 |
| print(5,2,9,sep='good') |
5good2good9 |
| print(5,2,9,sep='') |
529 |
| print(5)print(2) |
52 |
| print(5,end='ok'**)**print(2) |
5ok2 |
| print(2,3,sep=' ',end='\n') |
2 3 |
| print(' *')print(' ***')print('*****') |
|
| 常用数据类型:int,float,str,list |
| int |
整数 |
| float |
浮点数 |
| str |
字符串 |
| int("52") |
"52"是字符串,int("52")将得到数字52 |
| str(52) |
str(52)得到字符串"52" |
| float("52.1") |
得到浮点数52.1 |
| n=input() |
如果输入52,n会等于"52"input()函数返回值的类型是字符串 |
| print("pine"+"apple") |
pineapple |
| print("ok"*3) |
okokok |
| print("ok"+2) |
TypeError: must be str, not int |
| 字符串的切片 |
|
| s = "hello, guys"print(s[0]) |
h |
| print(s[5]) |
, |
| print(s[-1]) |
s |
| print(s[-2]) |
y |
| print(s[0:5]) |
hello |
| print(s[1:3]) |
el |