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