我是靠谱客的博主 简单鞋子,这篇文章主要介绍如何一个晚上自学完python(代码呈现加部分知识点总结),现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
msg='Hello,World!' print(msg) print(msg.lower()) #upper lower #引号的使用 print('Python') print("Hello"+",World"+"!") print("He said:'Good!'") print("He said:"Let's go!"") #反斜杠 #ctrl+/一键多行注释以及取消注释 #换行,三引号即可换行也可注释,看情况 print('''君不见, 黄河之水天上来。''') greet="nihao!" print(greet+"李思") #求长度,其中n算一个单位 print(len('hahan')) #索引 print("hello"[3]) #返回数据类型 #布尔类型的要大写 #空值类型 print(type(True)) #交互模式,python 进入,quit()退出 #数值类型的转换 """ user_age=int(input("请输入你的年龄")) user_age_after10=user_age+10 print(user_age_after10) #if else语句 注意冒号: if user_age>=60: print("可以退休了!") else: print("还要继续工作!") #多重if语句 if user_age<=18: print("少年") elif 18<user_age<60: print("中青年") else: print("老年") """ #优先级not->and->or #元组tuple 用圆括号 元组不可变,不可添加删除 number_tuple=("1","2") #相似 #列表操作 用方括号 逗号 number_list=["1","2"] number_list.append("3")#增加 number_list.remove("2")#去除 print(number_list) print(len(number_list))#求长度 number_list[0]="4"#把1换成4 print(number_list[0])#利用索引 price_list=[100,87,999,1] print(max(price_list))#min print(sorted(price_list)) # sorted_price=sorted(price_list) # print(sorted_price) #字典操作 可变 #注意:键的类型不可变 冒号: contacts={"xiaoming":"12334", "xiaohong":"12345"} print(contacts["xiaoming"])#输出值 contacts["xiaofang"]="12344"#直接增加词条 print("xiaoming" in contacts) print(len(contacts)) print(contacts.keys())#输出键 print(contacts.values())#输出值 print(contacts.items())#输出键值对 # query=input("请输入名字:") # if query in contacts: # print(contacts[query]) # else: # print("您输入的"+str(query)+"不在本字典里") # #迭代 temperature_dict={"qq":"35.6", "ww":"37.3"} for a,temperature in temperature_dict.items():#a那里相当于将键传给a if float(temperature)>=37.3: print(a+'n') #range范围函数 结束值不在序列范围 for i in range(5,10,1):#1是步长,默认1,其中1可以省略 print(i) print('n') #输出1-10之间的奇数 for j in range(1,10,2): print(j) total=0 for m in range(1,101): total=total+m print(total) #求平均值 while循环 # user_total=0 # user_count=0 # user_input=input("请输入数字,以q结尾终止:") # while user_input!='q': # num=float(user_input) # user_total+=num # user_count+=1 # user_input = input("请输入数字,以q结尾终止:") # result=user_total/user_count # print("平均值为:"+str(result)) #format方法 year="虎" name="张三" massage_content=""" 金{0}贺岁,欢乐祥瑞。 金{0}敲门,五福临门。 给{1}拜年啦! """.format(year,name) print(massage_content) #f-字符串 massage_content=f""" 金{year}贺岁,欢乐祥瑞。 金{year}敲门,五福临门。 给{name}拜年啦! """ print(massage_content) #def关键字定义函数 函数里面局部变量 def massage(year,name): massage_content = f""" 金{year}贺岁,欢乐祥瑞。 金{year}敲门,五福临门。 给{name}拜年啦! """ print(massage_content) massage("虎","张三") # #引用模块 # import statistics # print(statistics.median([1,2,3]))#注意[]括号 # #引用多个函数 # from statistics import median,mean # print(statistics.mean([1,2,3])) # #引用模块里面的所有函数 不推荐,容易模块函数名冲突 # from statistics import * # print(median([1,2,3])) #pypi.org网站对第三方库搜索 #终端 pip install #类 #构造函数 括号内第一个参数表示自身 class CuteCat: def __init__(self,cat_name,cat_age,cat_color): #注意def后面空格,两个下划线!!! self.name=cat_name self.age=cat_age self.color=cat_color def speak(self): print("喵"*self.age)#字符串重复 def eat(self,cat_food): print(f"{self.name}正在吃{cat_food}") cat1 = CuteCat("tom",2,"橙色") cat1.speak() cat1.eat('鱼') print(cat1.name,cat1.age,cat1.color) # 类的继承 # class 子类(父类): # super().__init__(属性)是调用父类的构造函数 # # 文件路径 # 绝对路径 # Unix系统/ # windows系统 # 相对路径 # 用.表示当前文件所在目录 # 用..表示更上一层的父目录

结果显示:

"D:PycharmPycharm ProjectvenvScriptspython.exe" "D:PycharmPycharm ProjectPython_study.py" 
Hello,World!
hello,world!
Python
Hello,World!
He said:'Good!'
He said:"Let's go!"
君不见,
黄河之水天上来。
nihao!李思
5
l
<class 'bool'>
['1', '3']
2
4
999
[1, 87, 100, 999]
12334
True
3
dict_keys(['xiaoming', 'xiaohong', 'xiaofang'])
dict_values(['12334', '12345', '12344'])
dict_items([('xiaoming', '12334'), ('xiaohong', '12345'), ('xiaofang', '12344')])
ww

5
6
7
8
9


1
3
5
7
9
5050

金虎贺岁,欢乐祥瑞。
金虎敲门,五福临门。
给张三拜年啦!


金虎贺岁,欢乐祥瑞。
金虎敲门,五福临门。
给张三拜年啦!


    金虎贺岁,欢乐祥瑞。
    金虎敲门,五福临门。
    给张三拜年啦!
    
喵喵
tom正在吃鱼
tom 2 橙色

进程已结束,退出代码0
 

其中部分需要作者输入的代码已注释,所以最后输出结果缺省了。

以上内容是博主学python过程中的代码段,只为总结记录,如有错误,希望的到指正。

最后

以上就是简单鞋子最近收集整理的关于如何一个晚上自学完python(代码呈现加部分知识点总结)的全部内容,更多相关如何一个晚上自学完python(代码呈现加部分知识点总结)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(44)

评论列表共有 0 条评论

立即
投稿
返回
顶部