python学习笔记与心得(一)

一、Python仪式:“hello world!”

1、print("hello world!") # 打印hello world!

2、windows系统的dos界面进行打印 hello world !操作:

在D盘使用TXT文本,创建hello world.py文本(PS:.py是告诉读者,此文件为Python文件,仅此而已)

在文本中,写入

print("hello world!")保存即可;

进入dos界面,切换到D盘目录 D:

使用dir 查询刚刚创建的文本文件,使用python "hello world.py.txt" ,即可打印出hello world!。

二、变量

name = "Oliver you"

name2 = name

name = "Nata Sha"

print(name,name2)

打印出的结果如下:Nata Sha Oliver you

原因分析:name 变量对应的值是“Oliver you”,而name2对应的是name,这里的理解是,name2通过name找到了对应值“Oliver you”,相当于name是中介。再往下,name重新变量值为"Nata Sha",此时name发生的改变,但是不影响name2,可以理解为中介变成了销售,但是name2已经认识了“Oliver you”。

三、格式化交互式语句

第一种模式:

#author:Oliver you

name = input("name:")

age = input("age:")

job = input("job:")

info = '''

-------- info of {_name} -------

name:{_name}

age: {_age}

job: {_job}

'''.format(_name =name,

_age =age,

_job =job,

_salary=salary)

print(info)

第二种模式:

name = input("name:")

age = input("age:")

job = input("job:")

info2 = '''

-------- info of {0} -------

name:{0}

age: {1}

job: {2}

'''.format(name,age,job)

print(info2)

四、if else 语句

1、明文

_username= 'oliver'

_password = 'abc123'

username = input("username:")

password = input("password:")

if _username==username and _password==password:

print("welcome user {name} login...".format(name=username))

else:

print("invalid username or password")

2、密文

import getpass

_username= 'oliver'

_password = 'abc123'

username = input("username:")

password = getpass.getpass("password:")

if _username==username and _password==password:

print("welcome user {name} login...".format(name=username))

else:

print("invalid username or password")

五、while Ture语句

第一种:循环一次结构

age_Oliver_you = 28

count = 0

while count

age_guess_oldboy:

print("think small...")

else:

print("think bigging")

count +=1

else:

print("you have tried too many times ... fuck off")

第二种:多次循环语句

age_Oliver_you = 28

count = 0

while count

age_Oliver_you:

print("think small...")

else:

print("think bigging")

count +=1

if count ==3:

countine_confirm = input("do you want to keep guessing?")

if countine_confirm !="n":

count = 0

六:for语句

1、for i in range(10):

print(i)

2、for i in range(10):

if i

age_Oliver_you:

print("think small...")

else:

print("think bigging")

else:

print("you have tried too many times ... fuck off")

心得:这几种Python语句并不难,主要在于如何的灵活运用,掌握几个重要的理论知识(1)break为结束此流程;(2)continue为继续此流程;(3)这几种流程语句可以叠加使用,从而可以达到意想不到的效果。

发表评论
留言与评论(共有 0 条评论)
   
验证码:

相关文章

推荐文章

'); })();