1. Python入門(mén)

[TOC]

語(yǔ)言的分類

  1. 編譯型語(yǔ)言

    需要在不同的平臺(tái)上編譯,生成針對(duì)不同平臺(tái)的專有的運(yùn)行代碼

  2. 解釋型語(yǔ)言

    不需要關(guān)注硬件底層,可以和不同的平臺(tái)溝通

語(yǔ)言的版本

2.7版本的語(yǔ)言將最后支持到2020年
當(dāng)前版本為3.6.1,已經(jīng)安裝
(當(dāng)前的安裝已經(jīng)集成選項(xiàng)可以直接自動(dòng)添加環(huán)境變量)

基礎(chǔ)語(yǔ)法

變量(variable)

  • 變量是什么?
    變量是個(gè)容器

  • 變量干什么用
    用于存儲(chǔ)數(shù)據(jù)到內(nèi)存

  • 變量怎么用
    賦值

  • 變量定義的規(guī)則

    • 變量名只能是 字母、數(shù)字或下劃線的任意組合
    • 變量名的第一個(gè)字符不能是數(shù)字
    • 以下關(guān)鍵字不能聲明為變量名
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']

用戶輸入

作業(yè)

# import getpass

# username = input('username:')
# password = getpass.getpass('password:')

# print(username,password)
# if username == 'scott' and password=='123':
#  print('welcome scott')
# else:
#  print('wrong')


# ------------------

age = 49
def play_game(i):
    while i < 3:
        guess_age = int(input('guess my age:'))
        i = i + 1
        if guess_age > age:
            print('Wrong,too old')
        elif guess_age < age:
            print('Wrong,too young')
        else:
            print('Right!!')
            i=0
            gift = input('do you like big sword?  Y/N:')
            if gift == 'Y':
                print('滿腦子騷操作,重新來(lái)')
            else:
                print('那你很棒棒哦')
                break

play_game(i=0)

while 1:
    print('小哥哥,還要接著玩嗎?')
    chose_play = input('Y/N:')
    if chose_play == 'Y' or 'y':
        play_game(i=0)
    else:
        print('你這樣亂搞就沒(méi)意思了')
        break
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容