一、创建txt文件
path = "C:\code\python\ "
file_path = path + 'pattern.txt'
file = open(file_path, 'w')
二、写入数据
file.write("Hello World")
file.close()
三、循环
count = 0
while (count < 9):
print 'The count is:', count
count = count + 1
for x in range(9):
print("x")
四、转为二进制
bin(12345).replace("0b", "")
s = "".join(f"{15:08x}")
print(s)
s = "".join(f"{15:016b}")
print(s)
s = "".join(f"{15:024o}")
print(s)
'{:08b}'.format(int(num))
五、定义函数
def my_len(str):
length = 0
for c in str:
length = length + 1
return length