python学习笔记入门
作者:互联网
@font-face{ font-family:"Times New Roman"; } @font-face{ font-family:"宋体"; } @font-face{ font-family:"Arial"; } @font-face{ font-family:"黑体"; } @font-face{ font-family:"Calibri"; } @font-face{ font-family:"DejaVu Sans Mono"; } @font-face{ font-family:"Noto Sans CJK SC"; } @list l0:level1{ mso-level-number-format:decimal; mso-level-suffix:tab; mso-level-text:"%1."; mso-level-tab-stop:15.6000pt; mso-level-number-position:left; margin-left:0.0000pt; text-indent:0.0000pt; font-family:'Times New Roman';} p.MsoNormal{ mso-style-name:正文; mso-style-parent:""; margin:0pt; margin-bottom:.0001pt; mso-pagination:none; text-align:justify; text-justify:inter-ideograph; font-family:Calibri; mso-fareast-font-family:宋体; mso-bidi-font-family:'Times New Roman'; font-size:10.5000pt; mso-font-kerning:1.0000pt; } h1{ mso-style-name:"标题 1"; mso-style-next:正文; margin-top:17.0000pt; margin-bottom:16.5000pt; mso-para-margin-top:0.0000gd; mso-para-margin-bottom:0.0000gd; page-break-after:avoid; mso-pagination:lines-together; text-align:justify; text-justify:inter-ideograph; mso-outline-level:1; line-height:240%; font-family:Calibri; mso-fareast-font-family:宋体; mso-bidi-font-family:'Times New Roman'; font-weight:bold; font-size:22.0000pt; mso-font-kerning:22.0000pt; } h2{ mso-style-name:"标题 2"; mso-style-noshow:yes; mso-style-next:正文; margin-top:13.0000pt; margin-bottom:13.0000pt; mso-para-margin-top:0.0000gd; mso-para-margin-bottom:0.0000gd; page-break-after:avoid; mso-pagination:lines-together; text-align:justify; text-justify:inter-ideograph; mso-outline-level:2; line-height:172%; font-family:Arial; mso-fareast-font-family:黑体; mso-bidi-font-family:'Times New Roman'; font-weight:bold; font-size:16.0000pt; mso-font-kerning:1.0000pt; } p.p{ mso-style-name:"普通\(网站\)"; margin-top:5.0000pt; margin-right:0.0000pt; margin-bottom:5.0000pt; margin-left:0.0000pt; mso-margin-top-alt:auto; mso-margin-bottom-alt:auto; mso-pagination:none; text-align:left; font-family:Calibri; mso-fareast-font-family:宋体; mso-bidi-font-family:'Times New Roman'; font-size:12.0000pt; } p.pre{ mso-style-name:"HTML 预设格式"; margin:0pt; margin-bottom:.0001pt; mso-pagination:none; text-align:left; font-family:宋体; font-size:12.0000pt; } span.msoIns{ mso-style-type:export-only; mso-style-name:""; text-decoration:underline; text-underline:single; color:blue; } span.msoDel{ mso-style-type:export-only; mso-style-name:""; text-decoration:line-through; color:red; } @page{mso-page-border-surround-header:no; mso-page-border-surround-footer:no;}@page Section0{ margin-top:72.0000pt; margin-bottom:72.0000pt; margin-left:90.0000pt; margin-right:90.0000pt; size:595.3000pt 841.9000pt; layout-grid:15.6000pt; mso-header-margin:42.5500pt; mso-footer-margin:49.6000pt; } div.Section0{page:Section0;}
Python学习笔记
1. 循环次数限制
lucky_num = 19
guess_count = 0
while guess_count<3:
print("guess count:",guess_count)
input_num = int(input("Input the guess num:"))
if input_num>lucky_num:
print("the real number is smaller.")
elif input_num<lucky_num:
print("the real num is bigger...")
else:
print("Bingo!")
break
guess_count += 1
else:
print("Too many retrys!")
2. for循环
lucky_num = 19
for i in range(3):
input_num = int(input("Input the guess num:"))
if input_num>lucky_num:
print("the real number is smaller.")
elif input_num<lucky_num:
print("the real num is bigger...")
else:
print("Bingo!")
break
else:
print("Too many retrys!")
3. %号表示【】
name = input("name:")
age = input("age:")
job = input("job:")
print("Information of %s:\nName:%s\nAge:%s\nJob:%s" %(name,name,age,job))
不建议使用+,占空间
三个单引号注释
在使用pycharm时,经常会需要多行代码同时缩进、左移,pycharm提供了快捷方式
1、pycharm使多行代码同时缩进
鼠标选中多行代码后,按下Tab键,一次缩进四个字符
2、pycharm使多行代码同时左移
鼠标选中多行代码后,同时按住shift+Tab键,一次左移四个字符
实例:
name = input("name:")
age = input("age:")
job = input("job:")
msg = '''
Information of %s:
Name:%s
Age:%s
Job:%s
''' %(name,name,age,job)
print(msg)
Strip()脱
Append追加''clear'清除空间, 'copy'复制, ' count() 方法用于统计字符串里某个字符出现的次数。可选参数为在字符串搜索的开始与结束位置。
', 'extend 函数用于在列表末尾一次性追加另一个序列中的多个值(用新列表扩展原来的列表)。
', 'index'索引, 'insert 函数用于将指定对象插入列表的指定位置。
', 'pop' 函数用于移除列表中的一个元素(默认最后一个元素),并且返回该元素的值。
, 'remove' 函数用于移除列表中某个值的第一个匹配项。
, 'reverse函数用于反向列表中元素。
', 'sort函数用于对原列表进行排序,如果指定参数,则使用比较函数指定的比较函数。
'实例:
name_list = ["alex","65brother","tenglan"]
name_list.append("ERIC")
name_list.insert(2,"66brother")
name1 = name_list[3]
print(name1)
print(dir(name_list))
print(name_list.index("65brother"))
print(name_list.count("65brother"))
print(name_list[2])
print(name_list.pop())
print(name_list.reverse())
name_list.append("*")
实例2:
name_list = [1,2,3,4,"Alex","John"]
a = name_list
name_list2 = ["Kevin","Mike"]
b = name_list2
a.extend(b)
name = "Nebula"
a.extend(name)
print(a)
4. 元组
5. 运算符
+,%余数,**返回x的y次幂,//返回商的整数部分
&,与;|,或;^,异或,一真一假即为真;<<左移除2;>>右移×2
实例:
a = [1,2,3,4,5,6]
b = (1,2,3,4)
print(type(a))
print(type(b))
6. 嵌套循环
for j in range(5):
for i in range(10):
if i<5:
continue
if j>3:
break
print(i)
7. 文件读写
'''f = open("test.log","w")
f.write("This is the first line\n")
f.write("This is the second line\n")
f.write("This is the third line\n")
f.write("This is the fourth line\n")
'''
f = open("test.log","r")
print(f.read())
f.close()
f = open("test.log","r")
for line in f:
print(line)
f.close()
Tips:Write直接覆盖原来文件
写读实例:
f = open("test.log","w+")
f.write("new line\n")
print(f.readline())
print("data:",)
f.close()
8. 字典
9. 不同种类的Python
(1)Cpython,C解释器,.pyc(字节码) 机器码 CPU
(2)jpython,java解释器,java字节码 机器码 CPU
(3)ironpython. C#
sys.argv:是一种列表类型,用于获取命令行参数的列表。
标签:入门,pt,python,笔记,mso,print,font,margin,name 来源: https://www.cnblogs.com/resort-033/p/12198269.html