1th Python Introduction 1.1 Basic introduction
L Code: The code appears to solve the problems in life
l Compiler Interpreter: The purpose is to have the interpreter translate the code into a computer-readable language
L Programming Languages: languages written in accordance with certain rules,
C Language and other
-Machine code: C
-byte code: Other
L Compile type and explanatory type
1.2 Python advantages
L CPython Common side conversion byte side run
L PyPy run the fastest after converting to bytecode
L Python is not only simple, but also full-class library
Summary: Install the interpreter to learn the language rules to write code to explain its run interpretation Python version
2nd Chapter Installation Pycharm
1) Select new environment using
2) Choose a second existing interpreter
3) Select Python path
2.3 Editing templates
#!/usr/bin/env python
#-*-Coding:utf-8-*-
The 3rd Chapter Hello word3.1 Exercises:
Rooster 5 Text Money One, hen 3 text Money A, Chick 3 only a penny, with 100 text money to buy 100 chickens, which cocks, hens, chickens must have, ask the rooster, hen, chicken to buy how many just just fill up 100 money?
"""
5* Cocks < 100
100 Hen <
1* Chick < 300
Rooster + hen + chick = 1000
"""
For I inrange (1, 21):
For x in range (1, 34):
For y in range (1, 301):
score= I * 5 +x * 3 + Y/3
If score = = 100:
Print (' rooster%s only, hen%s only, chick%s only '% (i,x,y))
Print (' Hello word ')
4th Chapter 4.1 Coded Information table
Coding |
Bytes |
Representation/bit |
Accommodate |
Use case |
Ascii |
1 |
00000010 |
256 |
Use 1 bytes = 8 bits to represent everything the computer can express. |
Unicode |
4 |
00000000 00000000 00000000 00000010 |
4294967296 |
Universal code, with 4 bytes = 32 bits To do the correspondence relationship |
UTF-8 |
3 |
10000000 00010000 00011010 |
16777216 |
Compress the universal code, using at least 1 bytes to represent |
GBK |
2 |
00000000 00000010 |
65536 |
Correspondence to the writing of Asian countries PS: Chinese 2 bytes = 16 bits |
4.2 Python2/python3 Differences:
L PY2: Interpreter default encoding ASCII
#-*-coding:utf-8-*-Interpreter default encoding Utf-8
Print (' King Crape Myrtle ')
L PY3: Interpreter default encoding Utf-8
Print (' Going to sleep ')
L PY2/PY3
#-*-CODING:GBK-*-
Print (' Going to sleep ')
5th Chapter Input Output 5.1 Print/input
Output:
Print ("You are the wind I am the Sand")
Input:
User =input ("Please enter your username:")
Ciphertext transmission:
Importgetpass
PWD =getpass.getpass ("Please enter password:")
The 6th Chapter Variable 6.1 format:
Example: variable name = value
User_name = [' Harry ',' Zhang San ']
Print(user_name)
6.2 Specifications:
L numbers, letters, underscores
L cannot start with a number
L cannot use Python's keywords
l See names and know the meaning; user_pwd = "XXX"
7th Common data Type 7.1 integers
age= 18
String:
Name= "Crape Myrtle"
# Get Violet
n1= Name[0]
N2= Name[1]
7.2 List
user_list= ["Crape Myrtle", "Er Kang", "18", "Mass", "Chick")
n3= User_list[0]
n4= user_list[1] # "Er Kang"
user_list= ["Crape Myrtle", "Er Kang", "18", "Mass", "Chick")
Forxxx in User_list:
Print (XXX)
Ifxxx = = ' 18 ':
Break
7.3 Dictionaries
user_info= {"name": "Crape Myrtle", "Age": 18}
n5= user_info["Name"]
n6= user_info["Age"]
user_info[' Count ']= 666
#{"name": "Crape Myrtle", "age": +, "Count": 666}
8th. Conditional Statement 8.1 Exercise: 10086 Smart Service Reminders
msg = "" "
Welcome Call 10086
1. Check your charges
2. Check the water meter
3. Human Services
""
chose = input (" >> Please enter the service to be queried ")
if chose = = ' 1 ':
print (" 1. Query this machine 2. Inquire about other people's phones 3. Query traffic ")
CHOSE_XIANMU = input (">> Please enter project")
Ifchose_xianmu = = ' 1 ':
Print ("Query this Machine")
Elifchose_xianmu = = ' 2 ':
print ("Find someone else's phone")
elif chose_xianmu== ' 3 ':
print (' Query traffic ')
else:
print ( ' re-enter ')
elif chose== ' 2 ':
print ("Query water meter")
elif chose== ' 3 ':
Print ("Human Services")
Else:
print ("re-enter")
8.2 Exercise: Enter a user name
# username = input (">> Please enter user name:")
# password = input (">> Please enter password:")
# number= 10
# if Username = = "Wang" and password = = str (123):
# print ("Login Successful")
# Else:
# Print ("Failed")
The 9th Chapter 9.1 Break/continu Difference of circular statement
L break-Terminates the current loop
L continu-Skip this cycle and continue the next cycle.
9.2 Exercise: Break
Count = 1
While True:
Print (count)
Count =count + 1
If count== 11:
Break
Count = 1
While True:
Print (count)
If count== 10:
Break
Count =count + 1
Count = 1
While True:
Print (count)
If count== 10:
Break
Count+=1
9.3 Exercise: Continu
# Output 1-10 on page, exclude
Method One:
Count = 1
While Count < 11:
If count== 7:
Count+=1
Continue
Print (count)
Count+=1
Method Two:
Count = 1
While Count < 11:
If count== 7:
Pass
Else
Print (count)
Count+=1
10th. Data type nesting 10.1 lists nested with each other
List =["Wang", "Xiao", [11,22,33]
N=LIST[1]
M=LIST[2][1]
Print (n)
Print (m)
Output:
c:\python3\python.exed:/python/untitled2/lianxi/1.py
Xiao
22
10.2 List Dictionary Nesting
List = [
"Wang",
{' name ': ' Xiao ', ' age ': 18},
[11,22,33]
]
list[1]["Age"]=20
Print (list)
Output
C:\python3\python.exe d:/python/untitled2/lianxi/1.py
[' Wang ', {' name ': ' Xiao ', ' Age ': 20}, [11, 22, 33]]
The 11th chapter of this week supplements: 11.1 Getpass
Getpass.getpass ciphertext input cannot be run in Python3, only at terminal
Import Getpass
Password = getpass.getpass (' >> enter password ')
if usname = = ' Wang ' and password = = 123:
Print ("OK")
Else
Print (' No ')
11.2 Input
Python3
user = input (' Please enter: ')
Python2
user = Raw_input (' Please enter user name: ')
Python_ Basic section (1)