The first week mainly introduced the history of Python, and some current applications.
Variable
Python's writing process will use a lot of data, that for the convenience of operation, it is necessary to use a simple name to represent the data, easy to reference in the next program, the variable is to represent a data (value) name.
1. Variable names can include letters, numbers, underscores, but numbers do not start
2, the System key words can not do variable name use
' Hello world! '
Print (VAR)
After execution
Hello world!
Character encoding
Character encoding from ASCII, to GB2312, GBK, GBK18030, to the present Unicode, because the English of Unicode occupies too much memory, so that after the UTF-8 optimization, a Chinese character takes up 3 bytes and an English character occupies 1 bytes.
If Else
1_username ='Doulen'2_password ='home1234' #声明用户名和密码的变量3 4Username = input ('Username:')5Password = input ('Password:') 6 7 ifUsername = = _username andPassword = =_password:8 Print('Welcome {name}, login ...'. Format (name=username)) #只要输入的用户名密码和预先存的一致 then output this passage .9 Else:Ten Print('username or password is wrong') #否则 Output This passage
While loop
1True_age = 242Count =03 whileCount < 3:4g_age = Int (input ('Age :'))5chances = 2-Count6 7 ifG_age = =True_age:8 Print('You got it!')9 BreakTen elifG_age >True_age: One Print('oops! think smaller, you had%s chances left'%(chances)) A Else: - Print('oops! think bigger, you had%s chances left'%(chances)) -Count +=1 the Else: - Print('You have guessed too many times')
Let the user choose to continue or terminate at their own discretion
1True_age = 242Count =03 whileCount < 3:4g_age = Int (input ('Age :'))5chances = 2-Count6 7 ifG_age = =True_age:8 Print('You got it!')9 BreakTen elifG_age >True_age: One Print('oops! think smaller, you had%s chances left'%(chances)) A Else: - Print('oops! think bigger, you had%s chances left'%(chances)) -Count +=1 the ifCount = = 3: -Countine_comfirm = input ('Do you want countine?y/n:') - ifCountine_comfirm! ='N': -Count = 0
Python Full stack development-week1