12.24

python学习
1.1#变量的修改
message = “hello python world!”
print(message)
message = “hello python crash course world!”
print(message)
12.24
#找错traceback有详细错误指导
#变量名只包括字母数字下划线。变量名可以为字母与下划线,但开头不能位数字
#变量名不能有空格,但可以使用下换线
#不要将python关键字和函数名用作变量名
1.2字符串
用单引号和双引号所引起的都为字符串
#修改字符串大小写
name=“ada lovelace”
print(name.title())
12.24
#首字母变大写title()upper()等小字母变大写
#lower()大写变小写输出
name=“Ada LOVElace”
print( name.upper())
print(name.lower())
12.24
1.3合并(拼接)字符串
first_name=“ada”
last_name=“lovelace”
full_name=first_name+""+last_name

print(full_name)

python12.24
#python中“+”代表拼接字符
first_name=“ada”
last_name=“lovelace”
full_name=first_name+""+last_name

print(“hello,”+ full_name.title()+"!")

12.24
1.4使用制表符与换行符来添加空白
#\t代表添加制表符如
print("\tpython")
12.24
#换行符的添加\n(与c语言相同)如
print(“languages\n\tpython\nC\njavascript”)

12.24
1.4删除空白 rstrip()
二列表
([])表示列表
bicycles=[‘trek’,‘cannocale’,‘redline’,‘specialized’]
print(bicycles)
12.24
#访问列表元素
bicycles=[‘trek’,‘cannocale’,‘redline’,‘specialized’]
print(bicycles[0])12.24
(等价于c语言中的列表,索引刚开始用0 )
使用列表中各值(数学运算加法模式)
bicycles=[‘trek’,‘cannocale’,‘redline’,‘specialized’]
massage=“My first bicycle was a “+bicycles[0].title()+”.”
print(massage)
12.24
#修改添加和删除元素
#修改列表元素
motorcycles=[‘honda’,‘yamaha’,‘suzuki’]
print(motorcycles)
motorcycles[0]=‘ducati’
print(motorcycles)
(赋值形式修改互换元素)
12.24
#在列表中添加元素(ducati,元素添加)
motorcycles=[‘honda’,‘yamaha’,‘suzuki’]
print(motorcycles)
motorcycles.append(‘ducati’)
print(motorcycles)
12.24
#在列表中插入元素
(insert()元素的插入)
motorcycles=[‘honda’,‘yamaha’,‘suzuki’]
print(motorcycles)
motorcycles.insert(0,‘ducati’)
print(motorcycles)
12.24
#在列表中添加元素
#方法append()添加元素
motorcycles=[]
motorcycles.append(‘honda’)
motorcycles.append(‘yamaha’)
motorcycles.append(‘suzuki’)
print(motorcycles)
12.24
从列表中删除元素del语句
motorcycles=[‘honda’,‘yamaha’,‘suzuki’]
print(motorcycles)
del motorcycles[0]
print(motorcycles)
12.24
也可以使用方法pop()删除元素
motorcycles=[‘honda’,‘yamaha’,‘suzuki’]
print(motorcycles)
popped_motorcycle=motorcycles.pop()
print(motorcycles)
print(popped_motorcycle)