Familiar with python and python
1, install python environment install python-3.6.3rc1-amd64 under windows, and then install python development tool PYcharm.
Experience: much simpler than java
1.1. Run the pip command to install the excel library in windows cmd: pip install xlrd. The system automatically downloads and installs the elrd library. Alternatively, you can use the plug-in Manager to download and install PYcharm.
TIPS: Very simple.
2. Character Set
ASCII 255 characters without Chinese characters 7 characters, single-byte
BG2312-80 7445 characters compatible with ASCII 16-bit, dual-byte
BIG5 13053 characters compatible with ASCII 16-bit, dual-byte
BG18030 27484 characters compatible with ASCII single-byte part compatible with ASCII, dual-byte, four-byte
Unicode is compatible with ASCII 16-bit, dual-byte, and unified with GB18030, BIG5, and ASCII
One use of UTF-8 unicode in hexadecimal format, extended, ASCII in 1 byte, Greek, accent in 2 byte, Chinese Character in 3 byte, secondary flat character in 4 byte
3, 2 hexadecimal
Each digit represents the sum of digits represented by the previous digit plus 1
0 0
1 1
2 10
3 11
4 100
5 101
6 110
7 111
8 1000
9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111
16 10000
4. Output of variables and print formats
2.1, the first format control method, using % s for placeholder Control
Name = input ("name :")
Age = int (input ("age :"))
Print (type (age ))
Job = input ("job :")
Salary = input ("salary :")
Print (type (salary ))
Info = '''
-------- Info of % s ---------
Name: % s
Age: % d
Job: % s
Salary: % s
''' % (Name, name, age, job, salary)
Print (info)
Advantages:
Disadvantages: not intuitive and difficult to maintain
Note: The data obtained by the input () function is of the string type and must be converted to another type only by force conversion.
''' Or "" has the same effect, Indicating multiple strings or comments.
Do not use this method unless you have
% D indicates that only numeric integers are received. If it is another type, an error is returned.
% F indicates that only the numeric floating point is received. If the input is another type, an error is returned.
2.2, second format control mode, format Function
Info2 = '''
----- Info of {_ name }-----
Name: {_ name}
Age: {_ age}
Job: {_ job}
Salary: {_ salary}
'''. Format (_ name = name, _ age = age, _ job = job, _ salary = salary)
Advantages: intuitive and easy to maintain
Disadvantages:
Note: print the variable name and the original variable name as much as possible
There is a "." Before format (variable value assignment)
2.3, the third format control method, using the digit placeholder control format
Info3 = '''
------ Info of {0 }------
Name: {0}
Age: {1}
Job: {2}
Salary: {3}
'''. Format (name, age, job, salary)
Print (info3)
Advantages:
Disadvantage: it is not intuitive, and the maintainability is better than the first method, but not as good as the second method.
5. python annotations
# Single line comment
''', "Multi-line comment, and the multiline string setting method ''' ------ info of {0 }------
Name: {0}
Age: {1}
Job: {2}
Salary: {3}
'''
6,Import Module
It can appear anywhere in the program.
Import module
Keyword Module name
To import multiple modules at the same time, you only need to separate them with commas before the module name:
Import module1, module2, module3 .......
It is best to use the import Statement to import modules in the following order: 1. python standard library module
2. python third-party module
3. Custom modules
From module (module name) import name (function name)
Import the specified function of a specified Module
From math import floor
7. if
_ Username = "cat"
_password = "a"
username = input("username:")
password = input("password:")
if username == _username and password == _password:
print("oye".format(name=username))
else:
print("fuck off baby!")
print(username, password)
Note:
= Exact equals
! = Indicates not equal
The python language strictly abides by indentation. If indentation is incorrect, the system reports an error.
Direct reference to variables is implemented by entering the variable name in {}, for example, {name}
8, loop, while,
8.1 for Loop
age_of_you=45
for i in range(3):
gass_age=int(input("gassage:"))
if gass_age==age_of_you:
print("oye")
break
elif gass_age<age_of_you:
print("too small")
else:
print("too big")
else:
print("try too many times.. fuck off")
Note:
Break: exit the Current Logical Block, such as if, for, while
While, for else syntax is unique to python
Count = count + 1 is equivalent to count + = 1 in python.
Range (10, X) X indicates the step size. The default value is 1.
8.2 while LOOP
age_of_you=45
count=0
while count<3:
gass_age=int(input("gassage:"))
if gass_age==age_of_you:
print("oye")
break
elif gass_age<age_of_you:
print("too small")
else:
print("too big")
count+=1
if count ==3:
countine_confirm=input("agein?Y|N:")
if countine_confirm != "n":
count=0
else:
print("thank you")
8.3,continue
for i in range(20):
if i <10:
print("loop:",i)
else:
continue
print(i)
Note: continue skips this loop and directly enters the next loop