Python 2022/05/28-14:08:50-Week6 学习笔记
Python
run a programm
Win + r , and write "cmd"
in the cmd "python"
if want exit :
exit()
improt
关于 import 的小结,以 time 模块为例:
1、将整个模块导入,例如:import time,在引用时格式为:time.sleep(1)。
2、将整个模块中全部函数导入,例如:from time import *,在引用时格式为:sleep(1)。
3、将模块中特定函数导入,例如:from time import sleep,在引用时格式为:sleep(1)。
4、将模块换个别名,例如:import time as abc,在引用时格式为:abc.sleep(1)。
Output
str = "0123456789"
print(str)
print(str[2:])
print(str * 2)
# string * 2 = stringstring
print(str[1:10:2])
# [begin : end : step]
print("--------------------")
print(str + "\n" + str)
print("--------------------")
print(str[0:10])
print("--------------------")
print(r"asdf\nasdf")
# add r the "\n" is disabled
Out:
0123456789
23456789
01234567890123456789
13579
--------------------
0123456789
0123456789
--------------------
0123456789
--------------------
asdf\nasdf
format
print("{:^2}".format(1))
print("{:2}".format(1))
print("{:-2}".format(1))
Out
1
1
1
Format格式
:n右对齐
:^n左对齐
浙公网安备 33010602011771号