Python学习小结 原创
Python小结内容:
0x00:Pycharm IDE
Pycharm 安装和一些配置可以参考这位博主的配置:https://www.jianshu.com/p/042324342bf4
有经济能力的用户尽量支持正版吧!
下载地址:https://www.jetbrains.com/pycharm/
写代码自然要配一个便于识别的字体,非要自己跟0与O、1与I,过不去吗?
字体Hack:https://sourcefoundry.org/hack/
0x01:代码兼容Windows和Linux
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:
0x02:学习一个:print
#!/usr/bin/env python
# -*- coding:utf-8 -*-
name = "test"
age = 4
print(name,age)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
name = input("input your name :")
age = int(input("input your age :"))
job = input("input your job :")
'''%s %d %f'''
msg = """
Infomation of user %s
------------------
Name : %s
Age : %d
Job : %s
--------End-------
"""%(name,name,age,job)
print (msg)
0x03:if、else、elif三两事
#!/usr/bin/env python
# -*- coding:utf-8 -*-
user = 'test'
passwd = 'test'
username = input("username:")
password = input("password:")
if user == username:
print ("username is correct...")
if passwd == password:
print("Welcome login ")
else:
print("password is invalid ")
else:
print("连用户名都没蒙对")
#!/usr/bin/env python
# -*- coding:utf-8 -*-
user = 'test'
passwd = 'test'
username = input("username:")
password = input("password:")
if user == username and passwd == password:
print("Welcome login ")
else:
print("username or password is invalid ")
0x04:循环小助手:for
#!/usr/bin/env python
# -*- coding:utf-8 -*-
age = 4
for i in range(10):
if i < 3:
guess_num = int(input("input your guess num :"))
if guess_num == age:
print ("Congratulations! you got it.")
break #跳出循环
elif guess_num > age:
print("Think smaller!")
else:
print("Think Big...")
else:
print("too many attempts ... bye")
break
#!/usr/bin/env python
# -*- coding:utf-8 -*-
age = 4
counter = 0
for i in range(10):
if counter < 3:
guess_num = int(input("input your guess num :"))
if guess_num == age:
print ("Congratulations! you got it.")
break #跳出循环
elif guess_num > age:
print("Think smaller!")
else:
print("Think Big...")
else:
#print("too many attempts ... bye")
#break
continue_confirm = input("Do you want too:")
if continue_confirm =='y':
counter = 0
continue
# pass #i = 0
else:
break
counter += 1 #counter = counter + 1
本文来自博客园,作者:饕餮人,转载请注明原文链接:https://www.cnblogs.com/taotieren/p/18457804