First, Hello World
The Hello world notation under Python:
1 # !/usr/bin/env python 2 # _*_ coding:utf-8 _*_ 3 # Author:taoke 4 Print ("Hello World!!! ")
[#!usr/bin/env Python] explains:
Looking for Python environment variables under Linux system
[# _*_ Coding:utf-8 _*_] Explanation:
The current file uses UTF-8 encoding
[# Author:taoke] Explanation:
Yes, that's me >_<
Second, the variable
Rules for variable definitions:
1. Variable names can only be any combination of numbers, letters, and underscores
2. The first character of a variable name cannot be a number
3. The following keywords cannot be used as variable names
[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]
(There is no concept of a constant in Python, and a personal definition uses a variable with a variable name in all capitals as a constant)
Third, the Code
ASCII encoding 255 1bytes
-->1980 GB2312 2bytes
-->1995 GBK1.0 2w+
-->2000 GB18030 27xxx
-->1994 Unicode 2bytes (Universal code)
-->utf8
Ch:3bytes
Iv. notes
1. # comment Content
2, ""
Comment Content
’’’
V. User interaction Program (input and formatted output)
string concatenation try not to use,
The output is formatted in the following three ways:
1 #!/usr/bin/env python2 #_*_ coding:utf-8 _*_3 #Author:taoke4 5Name = input ("Name:")6Job = input ("Job:")7Salary = input ("Salary:")8age = Int (input ("Age :"))9 Print(Type (age), type (str ))TenOUTSTR1 =""" One ------Info%s------- A name:%s - job:%s - salary:%s the age:%d - """%(name,name,job,salary,age) -OUTSTR2 =""" - ------Info {_name}------- + Name:{_name} - Job:{_job} + Salary:{_salary} A Age:{_age} at """. Format (_name =name, -_job =Job, -_salary =salary, -_age =Age ) -OUTSTR3 =""" - ------Info {0}------- in name:{0} - Job:{1} to salary:{2} + Age:{3} - """. Format (name, the Job, * salary, $ Age )Panax Notoginseng - Print(OUTSTR3)
Six, guessing the age of the game (while and if)
1 #!/usr/bin/env python2 #_*_ coding:utf-8 _*_3 #Author:taoke4Reallyage = 435Guessage =06 whileGuessage! =Reallyage:7guessage = Int (input ("Please input The Guess Age:"))8 ifguessage<Reallyage:9 Print("it's small.")Ten elifGuessage>Reallyage: One Print("big.") A Else: - Print("guess right.")
Seven, the work
1, write the login interface
1) Enter user name password
2) Display welcome message after successful login
3) The error three times after the lock (ie: the output user has been locked)
1 #!/usr/bin/env python2 #_*_ coding:utf-8 _*_3 #Author:taoke4 5Username ='Huangye'6Password ='123456'7flag=08Count =09 whileTrue:TenInputName = input ("User name:") OneInputpassword = input ("Password:") A ifInputName = =Username: - ifCount<3: - ifInputpassword = =Password: the Print("Welcome {_username} use". Format (_username =inputname)) - Break - Else: -Count+=1 + Print("incorrect user name or password") - Else: + Print("The user has been locked") A Else: at Print("incorrect user name or password")
Python basic Syntax 1