程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[useful Python knowledge] - simple and easy to operate Python knowledge

編輯:Python

Point a favor and leave a note !!

Catalog

One 、 Get computer user name

Two 、 String case

3、 ... and 、 Operation conditions (|,&==or,and)

Four 、 Determine whether to connect to the Internet

5、 ... and 、 Open the specified web address using the default browser

One 、 Get computer user name

import getpass # The import module
user_name = getpass.getuser()
print(user_name) # Print user name 

Two 、 String case

a= 'abcdeFGHIJK'
print(a.lower()) # Change to lowercase abcdefjhijk
print(a.upper()) # Capitalize ABCDEFGHIJK

3、 ... and 、 Operation conditions (|,&==or,and)

# | == or As long as one condition is satisfied, it is True
# & == and If all conditions must be met, it is True
# '''| or'''
q = input(' Excuse me, are you Grandpa 、 grandma 、 Father or mother :')
if (q == ' grandpa ') | (q == ' Dad '): # As long as one condition is met True Then carry out
print(' You are a male ')
else:
print(' You are a woman ')
e = input(' Excuse me, are you Grandpa 、 grandma 、 Father or mother :')
if (e == ' grandpa ') or (e == ' Dad '): # As long as one condition is met True Then carry out
print(' You are a male ')
else:
print(' You are a woman ')
# '''& and'''
r = input(' How many points did you get in the exam ( Full marks 100):')
if (r > '60') & (r < '80'): # All conditions must be met True Will execute
print(' pass ')
t = input(' How many points did you get in the exam ( Full marks 100):')
if (t > '60') and (t < '80'): # All conditions must be met True Will execute
print(' pass ')

Four 、 Determine whether to connect to the Internet

import pywifi
from pywifi import const
wifi = pywifi.PyWiFi() # Grab the network card interface
iface = wifi.interfaces()[0] # Access to network card
if iface.status() == const.IFACE_CONNECTED:
print(' Connected to the network ')
else:
print(' Network error !!!')

5、 ... and 、 Open the specified web address using the default browser

import webbrowser
webbrowser.open('www.baidu.com')

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved