python学习小结_190611

第一天的学习收获很多,上午主要讲了python和有关于编程的基础知识,大家都稍有基础所以后面较为简略。后半段为python语言的基础知识,包括常量变量,数据类型,流程控制等。下午则主要是字符串和列表的一些基础操作,层次分明,收获颇丰。

AM

name = "tank"
print(name)
print('helle world')

# id,type,value

# Python小计数池
# 在变量值产生后的制定范围内 在内存中事先开辟一块内存空间 然后分别把指定范围内的变量存放进去
# Python的优化机制
x = 10
y = 10
print(id(x))
print(id(y))

name = "lv"

print(type(x))
print(type(name))
# 判断值是否相等
print(x == y)
# 判断id是否一致
print(x is y)

# 常量(常量也是变量)在py中只要是大写的变量都是常量
SCHOOL = "AHPU"

# 用户与程序交互
name = input("输入你的用户名")
password = input("输入密码")

print(name,password)

# 数字类型
# 整形
# 浮点
num = 100
num1 = 15.0
print(type(num), type(num1))

print("li" * 5)

# 列表类型
student = ["张嫚嫚", "tank", "111", 11, []]

# for循环
list1 = [1, 2, 3, 4, 5]
for line in list1:
print(line)

# range
for i in range(10):
print(i)

dic1 = {'name': 'kermit', 'age': 18, 'sex': 18}
for key in dic1:
print(dic1[key])
PM
# 字符串的操作==================================

# 定义
list1 = ["li", 22, "anhui"]
str1 = "my name is liwei"
str2 = " my name is xxx "

# 1 按索引取值 正向和反向
print(list1[1])
print(list1[-2])

# 2 切片取值 顾头不顾尾 步长
print(str1[3])
print(str1[3:7])
print(str1[3:10:2])

# 3 长度len
i = len(str1)
print(i)

# 4 成员运算in和not in
print('i' in str1)

# 5 移除空白strip
print(str2.strip())

# 6 切分split
list2 = str1.split(' ')
print(list1)

# 7 循环
for line in str1:
print(line)
# 默认换行参数等于换行符
print(line, end=" ")

#===========================================================================================
# 需要掌握的方法
# 定义
str3 = "**my nameis * "
# 1 strap rstrap rstrip
print(str3.strip())
print(str3.strip('*'))
print(str3.rstrip('*'))

# 2 lower upper
print(str3.upper())

# 3 startswitch endswitch 判断字符串首尾是否成立
print(str3.startswith('*'))
print(str3.startswith('**myn'))

# 4 format3种玩法

# (1)按照位置替换
str4 = 'my name is {2},my age is {1}' # (2)安装索引替换
str4 = str4.format("liwei",22,"zhangzhao")
print(str4)
str4 = 'my name is {name},my age is {age}' # (3)安装名称替换
str4 = str4.format(name = "liwei",age = 22)
print(str4)

# 5 spllit rsplit
print(str4.split())
print(str4.rsplit())
# 6 join对列表中的数据按照某种表示进行拼接
name1 = 'liwei'
age1 = '22'
print(':'.join([name1, age1]))

# 7 replace
str5 = "old new"
# 括号中第一个参数是旧参数 第二个是新的,新的替换旧的
str5 = str5.replace('new','old')
print(str5)

# 8 isdigit
ID = "nk"
print(ID.isdigit())

#=============================================================================================
# 列表的内置方法
list1_1 = ['liwei',22,'male',10]
# 优先掌握的操作
# 1.按索引存取值
print(list1_1[3])
print(list1_1[-1])

#2.切片(渡头不顾尾)步长
print(list1_1[0:4])
print(list1_1[0:4:2])

# 3.长度
print(len(list1_1))

# 4.成员运算in和not in
print("liwei" in list1_1)
print("liwi" in list1_1)
# 5.追加
list1_1.append("ojbk")
list1_1.append("youyou")
print(list1_1)

# 6.删除 pop取出列表中的值 remove删除列表中的值
# print(list1_1.pop()) # 默认-1
# print(list1_1.pop(0))
level = list1_1.pop(-3)
print(level)
print(list1_1)

name = list1_1.remove("liwei")
print(name)
print(list1_1)

# 7.循环
for line in list1_1:
print(line)

HOMEWORK
 1 name = "  aleX"
 2 
 3 # 1)
 4 print(name.strip())
 5 
 6 # 2)
 7 print(name.startswith("al"))
 8 
 9 # 3)
10 print(name.endswith("X"))
11 
12 # 4)
13 print(name.replace("l","p"))
14 
15 # 5)
16 print(name.split("l"))
17 
18 # 6)
19 print(name.upper())
20 
21 # 7)
22 print(name.lower())
23 
24 # 8)
25 print(name[1])
26 
27 # 9)
28 print(name[0:3])
29 
30 # 10)
31 print(name[4:6])
32 
33 # 11)
34 print(name[4]+"的位置为",end=" ")
35 print(id(name[4]))
36 
37 # 12)
38 print(name[0:len(name)-1])

 运行结果:

 

 
posted @ 2019-06-11 22:28  时无英雄  阅读(195)  评论(0编辑  收藏  举报