WEEK 1 -- day1 Python study notes, -- day1python
Why Learning Python?
Areas of expertise in Python
1. python2.x does not support Chinese encoding. The default encoding format is ASCII code, while python3.x supports Unicode encoding and Chinese. The variable name can be Chinese, for example: age = 19 (but not recommended ).
2. Define constants in python: Capital all variable names, for example, PIE = 3.14
3. Evolution of encoding formats:
4. Interactive input in python:
Import getpass # import the ciphertext Module
Username = input ("your name :")
Age = input ("your age :")
# Password = input ("set your password :")
Password = getpass. getpass ("set your password :")
Print ("info:", username, age, password)
5. multiline output or multiline comments in Python (String concatenation)
(1) ''' three quotation marks can indicate multi-line comments
’’’ this is a program for you
and you will get help from here,
click this button’’’
(2) The value of three quotation marks (multiple rows) can also be assigned to a variable.
info=’’’ hello World,
name=wujian
age=22
hello!!!”’
print(info)
(3) "'" is used for formatting multiple rows.
Username = input ("your name :")
Age = input ("your age :")# Age = int (input ("your age:") to convert the character type to the numeric type. Similarly, you can use the str () function to convert other types to the string type.
Salary = input ("you salary :")
Info = "'------------------- info of % s -------------
Name: % s
Age: % s
Salary: % s
'% (Username, username, age, salary)
# % S is the placeholder, and the subsequent variables must correspond to the placeholder in sequence. Similarly, % d indicates that the output is a number, and % f indicates that the output is a floating point decimal.
Print (info)
Or:
info2=”’ -------------------info of {_name}-------------
Name:{_name}
age:{_age}
salary:{_salary}
”’ .format(_name=username,_age=age,_salary=salary)
print(info2)
Or
Info3 = "'----------------- info of {0 }-------------
Name: {0}
Age: {1}
Salary: {2}
"'. Format (username, age, salary)
# {Number} corresponds to the following variables in sequence
Print (info3)
6. Play the game of age prediction: You are allowed to give five guesses. If you still can't guess the chance, you will be prompted, "you have tried multiple times and rolled off fuck off"
Trial version: If you haven't guessed it three times, you will be prompted if you want to continue.
7. About the for Loop:
for i in range(10):
print(“loop:” ,i)
For j in range (1,100, 2) #1-100, with an interval of 2 and an odd number of outputs
Print ("loop:", I)
8. continue: ends this loop and goes back to continue executing the next loop.
Break: jump out of the entire Loop
9. Job 1: Write the login interface. After the authentication is successful, the welcome information is displayed. After the error is entered three times, the interface is locked.
Job 2: Level 3 menu: You can choose to go to each sub menu in turn, --- use the dictionary and list