1, the definition of variables:
(1) variable name can only be any combination of letters, numbers or underscore
(2) The first character variable names can not be digital
(3) the following keywords can not be declared variable name
['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']
2, define constants:
Variable name capitalization. It can be changed, but it should not be changed.
3, Character Encoding:
The binary and character link
(1) ASCII American Standard transform coding information
1 character 1 byte, i.e., 8 bits.
(2) Unicode Unicode
1 character 2 bytes, i.e. 16 bits.
(3)UTF-8
Encoding type | It represents the number coding | Placeholder |
ASCII | 255 | 1bytes |
GB2312 | 7000+ | |
GBK1.0 | 20 000+ | |
GB18030 | 27 000+ | |
UTF-8 | a: 1bytes zn:3bytes |
4, Python3.x and Python2.x difference:
Python3.x default Chinese, UTF-8
Python2.x default ASCII
Display Chinese characters in Python2.x in: # - * - coding: utf-8 - * -
5 comments
(Python same function in single and double quotation marks)
When looking at the line: # annotated content
Multi-line comments: '' 'annotated content' ''
It can also be used to print multiple lines of characters, such as:
msg = '''abcd
efg
hji
'''
print(msg)
6, user input, an output format
INPUT = name ( "name:")
Age = INPUT ( "Age:")
Job = INPUT ( "Job:")
info = '' '
---- ---- S% info of
the Name:% S
Age: S%
the Job:% S
'' '% (name, name, Age, Job)
Print (info)
# same format output, more usually
INF02 =' ''
---- INF02 of the _name} {
the name: { } the _name
Age:} {_age
the Job: _job {}
'' '.format (= the _name name,
_age = Age,
_job = Job)
Print (INF02)
7, enter the password hidden
Use getpass module
import getpass
username = input("username: ")
password = getpass.getpass("password: ")
print(username, password)
8, while circulation
COUNT the while <. 3:
guess_age = int (INPUT ( "Age GUESS:"))
IF guess_age == age_of_man:
Print ( "correct")
BREAK out of the current cycle #
elif guess_age> age_of_man:
Print ( "Think Smaller")
the else:
Print ( "of Think Bigger")
COUNT = 1 +
the else: # after the above cycle is complete implementation of
print ( "you have tried too many times")
9, for circulation
(1)
age_of_man = 56
for i in the Range (3): # write cycle a few times, starting from 0
guess_age = int (the INPUT ( "GUESS Age:"))
IF guess_age == age_of_man:
Print ( "correct")
BREAK
elif guess_age> age_of_man:
Print ( "Think Smaller")
the else:
Print ( "Think Bigger")
the else:
Print ( "you have have Tried TOO MANY Times")
'' '
number of steps:
for I in Range (0, 10, 2)
2 is the number of steps corresponding to every other computing a result of printing 02,468
'' '
(2)
I in Range for (0, 10):
IF I <. 3:
Print ( "Loop:", I)
the else:
Continue # out of this cycle, the next cycle continues. break the current cycle is the end of the entire
print ( "hehe")
10, work
Readme (blog address + brief program, using the method) + + flowchart Code
1 blog
2, the preparation of landing Interface
(1) Enter the user name and password
(2) displays a welcome message authentication success
(3) After 3 unsuccessful attempts to lock
Need: lock file + user name, password file
3, multi-level menu
(1) three-level menu
(2) can select each sub-menu to enter
(3) required new knowledge: lists, dictionaries