Python study notes: 1. First acquaintance with python

4.26
Today's Content Outline
1. Get to know the computer for the first time. CPU memory hard disk
2. First acquaintance with python
3.python development history and influence
4. Classification of python
5. Types of python
6. Variables
7. Constants
8. Notes
9. Basic knowledge of the types of numbers
10.input
11.if
12.while
 
One equal sign is an assignment operation, and two equal signs are comparison values
 
 
######Today's Notes######
Outline of today's content.
1. Get to know the computer for the first time. CPU memory, hard disk, operating system
CPU: brain, central processing unit, computing center.
Memory: Temporarily store data for CPU operation.
    Pros: Fast read speed.
    Disadvantages: small capacity, high cost, and disappears immediately after power failure.
Hard Disk: Stores data for a long time, a large amount of data. 500G, 1T, 2T, blockbuster, small video.
    Advantages: large capacity, low cost, power failure does not disappear. ,
    Disadvantage: slow read speed.
Operating system: deployment, the operation of each hardware.
    windows,linux,cenos,mac,。。。
 
 
2. First acquaintance with python.
 
3, python development history to influence.
    python: beautiful, clear, simple.
    1 big difference:
        python2x: The source code is not standardized, the source code is chaotic, and there are many repeated codes.
        python3x: Reorganized source code, source code specification, beautiful, clear and simple.
        
        
4. Classification of Python.
Compiled:
    Compile the code all at once into a secondary system, and then run it.
    Advantages: high execution efficiency.
    Disadvantages: slow development efficiency, not cross-platform.
    Representative language: C.
Explanation:
    The code is interpreted line by line, the interpretation is called binary, and then run.
    Advantages: high development efficiency, third-party library, cross-platform.
    Disadvantages: low execution efficiency.
    Representative language: python.
    
5. Types of Python.
 
5.5 Run the first python file:
    Python space file path, press Enter.
    python2x: default encoding ascii,
            Display Chinese: the first line: # -*- encoding: utf-8 -*-.
    python3x: The default encoding is utf-8,.
    python2x: print 'content' print('content')
    python3x: print('content').
    
6. Variables.
    #Variable: Store the intermediate result of the calculation for subsequent code use.
    Variable setting rules:
        1, must be any combination of letters, numbers and underscores.
        2. It cannot start with a number.
        3. It cannot be a keyword in python.
        ['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']
        4. The variable cannot be in Chinese.
        5, the variable can not be too long.
        6. Variables are descriptive.
        AgeOfOldboy = 56
        NumberOfStudents = 80
        #underscore
        age_of_oldboy = 56
        number_of_students = 80
#Constant: A quantity that has not changed. Variables that default to all uppercase are constants.
# ID number, π,
#Comment.
# Help you understand other people's code and recall your own code.
#Single-line comment: # Multi-line comment ''' commented content''' """ commented content """
 
#Basic data type:
int number, integer. used for calculation. + - * / % //
str ; String. In python, anything enclosed in quotes is a string.
    print('this is a string')
    print("This is a string")
 
    msg = '''
    The bright moonlight in front of the bed,
    Suspected to be frost on the ground.
    '''
String: can be added, can be multiplied.
str + str : Concatenation of strings.
print(msg)
Multiply:
str * int
msg = 'strong'
#print(msg * 8)
 
#bool True False Two states: determine whether the code is true or false.
 
#print(3 > 2)
#print(3 > 4)
 
#print('True')
#print(True)
# Determine what data type this object is type()
#print('True',type('True'))
#print(True,type(True))
 
 
10. Enter user input.
 
 
 
11,if。
other languages:
    if (condition) {result}
if condition:
    result
    
 
12,while。
#while
Terminate the loop:
    1. Change the conditions.
    2, break. (Directly end the loop.)
Keywords: break,
        continue, end this loop and continue to the next loop.
 
######Today's Code######
# -*- encoding: utf-8 -*-
# print('Hello China')
'''
print(1+2+3+6+7+8+101)
print((1+2+3+6+7+8+101)*3/5)
print(((1+2+3+6+7+8+101)*3/5)*4/8)
 
a = 1+2+3+6+7+8+101
b = a*3/5
c = b*4/8
print(c)
 
#Variable: Store the intermediate result of the calculation for subsequent code use.
a_ = 4
a*c = 3
___ = 22
_+ = 23
_ _ = 15
12e = 66
 
age1 = 12
AGE2 = age1
age3 = age2
age2 = 23
print(age1,age2,age3) # 12 23 12  12 12 12
'''
#Constant: A quantity that has not changed. Variables that default to all uppercase are constants.
# ID number, π,
#Comment.
# Help you understand other people's code and recall your own code.
#Single-line comment: # Multi-line comment ''' commented content''' """ commented content """
 
#Basic data type:
"""
print('this is a string')
print("This is a string")
 
msg = '''
The bright moonlight in front of the bed,
Suspected to be frost on the ground.
'''
print(msg)
"""
 
msg1 = 'Old Boys Education'
msg2 = 'is the best training institution'
#print(msg1+msg2)
msg = 'strong'
#print(msg * 8)
 
#bool True False Two states: determine whether the code is true or false.
 
#print(3 > 2)
#print(3 > 4)
 
#print('True')
#print(True)
# Determine what data type this object is type()
#print('True',type('True'))
#print(True,type(True))
'''
name = input('Please enter your name:')
age = input('Please enter your age:')
print(name,age,type(name),type(age))
'''
 
#if
#single if
'''
print(111)
if 3 > 2:
    print(666)
print(333)
'''
#if else
'''
name = input('Please enter your name:')
if name == 'lord':
    print('Old iron, no problem')
else:
    print('Ill be cured....')
 
#if elif ...
num = int(input('Please enter your choice:')) # str ---> int str is all numbers
if num == 4:
    print('Lunch, please')
elif num == 5:
    print('Dinner, please')
elif num == 6:
    print('Health care, walk up')
'''
#if elif ... else
'''
num = int(input('Please enter your choice:')) # str ---> int str is all numbers
if num == 4:
    print('Lunch, please')
elif num == 5:
    print('Dinner, please')
elif num == 6:
    print('Health care, walk up')
else:
    print('Give you a chance to catch...')
'''
    
# nested
'''
num1 = input('Please enter a number')
if num1 == '3':
    num2 = input('Please enter a number:')
    if num2 == '5':
        print('This can be guessed correctly')
    else:
        print('Keep working hard')
 
score = int(input("Enter score:"))
if score > 100:
    print("I wipe, the highest score is only 100...")
elif score >= 80:
    print("B")
elif score >= 90:
    print("A")
elif score >= 60:
    print("C")
elif score >= 40:
    print("D")
else:
    print("Too stupid...E")
'''
'''
while condition:
    result
 
 
while True:
    print('Serve the country with loyalty')
    print('Pink Memories')
    print('cool')
    print('The wind is blowing')
 
 
flag = True
while flag:
    print('Serve the country with loyalty')
    print('Pink Memories')
    print('cool')
    flag = False
 
flag = True
while flag:
    print('Serve the country with loyalty')
    print('Pink Memories')
    print('cool')
    flag = False
    print('first time')
 
 
count = 1
flag = True
while flag:
    print(count)
    count = count + 1 # count += 1
    if count == 101:
        flag = False
 
count = 1
while count < 101:
    print(count)
    count = count + 1 # count += 1
 
count = 0
while count < 101:
    print(count)
    count = count + 2
    
count = 0
while count < 101:
    if count % 2 == 0:
        print(count)
    count = count + 1
 
while True:
    print(111)
    print(222)
    break
    print(333)
print(666)
 
while True:
    print(111)
    print(222)
    continue
    print(333)
print(666)
'''
#break while loop computes 1+2+3+4...+100
count = 1
sum = 0
while True:
    sum = sum + count
    count = count + 1
    if count == 101:break
    
print(sum)
    
    
    
    
    
    
    
    
 
 
 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324920746&siteId=291194637