python-1day
生活随笔
收集整理的這篇文章主要介紹了
python-1day
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
python筆記
<head> 打印命令 print
----print 打印命令------
定義變量格式 XXX = ("XXX")
引用格式1:print(XXX)
引用格式2:print('輸入任何內(nèi)容加引號',XXX)打印字符類型
print(type(XXX))實(shí)驗(yàn)
name = "Hello World!"
print(name)
print('my name is',name)
返回結(jié)果
Hello World!
my name is Hello World!
------------------------------
</head>
<head> 交互式輸入 input
AAA = input("AAA:")
BBB = input("BBB:")
print(AAA,BBB)</head>
<head> 格式打印
#%s (全拼string) (驗(yàn)證字符)
#%d 整數(shù) (驗(yàn)證整數(shù))檢測驗(yàn)證數(shù)據(jù)類型 錯(cuò)誤則報(bào)錯(cuò)
#%f 浮點(diǎn)數(shù)
.format 格式2、3 指定{}中內(nèi)容=某個(gè)變量---------格式打印1-------------
AAA = '111'
BBB = '222'
CCC = '333'test = '''
%s
%s
%s
'''%(AAA,BBB,CCC)
print(test)實(shí)驗(yàn)
name = 'gaoliandi'
ago = '30'
work = 'IT'info = '''
%s
%s
%s
'''%(name,ago,work)
print(info)--------格式打印2--------------
AAA = '111'
BBB = '222'
CCC = '333'test = '''
{aaa}
{bbb}
{ccc}
'''.format(aaa=AAA,bbb=BBB,ccc=CCC)
print(test)--------格式打印3--------------
AAA = '111'
BBB = '222'
CCC = '333'test = '''
{0}
{1}
{2}
'''.format(AAA,BBB,CCC)
print(test)</head>
<head> 字符轉(zhuǎn)換 int str
int(XXX) 轉(zhuǎn)化整數(shù)
str(XXX) 轉(zhuǎn)化字符</head>
<head> 利用交互式輸入賬戶密碼(加密) 判斷賬戶密碼是否正確
筆記
import getpass 調(diào)用getpass模塊 import加載模塊命令
模板 password = getpass.getpass("password:")
if (判斷條件,不縮進(jìn)) 子命令行必須縮進(jìn)
else: (否則執(zhí)行條件,不縮進(jìn)) 子命令行必須縮進(jìn)實(shí)驗(yàn)
import getpass
_username = "gaoliandi"
_password = "abc123"
username = input("username:")
password = getpass.getpass("password:")if _username == username and _password == password:print('Welcone user {name} login...'.format(name=username))
else:print("Invalid username or password!")</head>
<head>
</head>
<head>
</head>
<head>
</head>
<head>
</head>
<head>
</head>
<head>
</head>
<head>
</head>
<head>
</head>
<head>
</head>
<head>
</head>
?
轉(zhuǎn)載于:https://www.cnblogs.com/gaoshuji/p/7771779.html
與50位技術(shù)專家面對面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的python-1day的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python列表的append/ente
- 下一篇: 大话设计模式Python实现-观察者模式