这是这些天学python的笔记,为加深印象,我把学过的怕忘的知识整理记录下来。
用的教材是《Python语言程序设计(英文版)》
第一句学的语言:
print("Welcome to Python")
Python的句尾都是没有标点符号(punctuation)的,但是在循环语句中是有标点符号。
Python是一门注意缩进的语言。在体内的句子可以用tab和space来进行缩进,但要按照一定的规则,否则就会报错。可能print语句空格和没有空格就会造成结果很大的区别,例如下面此条语句:
squares = []
for value in range(1,11):
square = value**2
squares.append(square)
print(squares)
与的区别
squares = []
for value in range(1,11):
square = value**2
squares.append(square)
print(squares)

下面都是关于一些,缩进编译器报错提示
1. TabError: inconsistent use of tabs and spaces in indentation
错误原因:tab和space混用不当,造成缩进问题。我试了一下,貌似用体内用tab缩进后再用space缩进不会报错,但若先用space再用tab则可能造成该错误。
2. SyntaxError: invalid syntax
错误原因:语法错误,一行的最前方如果是...表明还在体内,此时若要写体外语句,则需要按下回车,最前方为>>>时则可以另起一体。
3. IndentationError: unexpected indent
错误原因:不需要缩进时缩进
4. IndentationError: expected an indented block
错误原因:该缩进时没缩进
5.循环后不必要的缩进
2.1 title,upper,lower三个字符函数

bicycles = ['trek', 'cannondale', 'redline', 'specialized']
print(bicycles[0])
append函数,删除函数
motorcycles = ['honda', 'yamaha', 'suzuki']
print(motorcycles)
motorcycles.append('ducati')
print(motorcycles)
Append往表中最后一位添加一个元素
Insert往表中添加一个元素,格式为 列表a。insert(n,’字符’)
Pop函数的用法,变量a=变量a.pop()
remove函数的用法。列表a。remove(“字符”)
>>> digits = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
>>> min(digits)
0
>>> max(digits)
9
>>> sum(digits)
45
定步长:函数range()
even_numbers = list(range(2,11,2))
print(even_numbers)
2 4 6 8 10
squares.py
squares.py
squares = []
for value in range(1,11):
square = value**2
squares.append(square)
print(squares)
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]