Python---Basic


The birth of python
: The founder of python is Guido Van Rossum (Uncle Turtle)

Comparison of python2X and python3X:
python2x: source code is not standardized, source code is confusing, there are many repeated codes, python2x: the default encoding method ascii, python2X does not support Chinese , display the first line of Chinese to add: - * - encoding: utf - 8 -
*-
python3x: Reorganize the source code, source code specification, beautiful, clear, simple
variables:
# Variable: Store the intermediate results of the calculation for subsequent code use .
Variable setting rules:
1. It 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 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

# -*- 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)
# variables: Store intermediate results of computations for use by subsequent code.
a = 1 + 2 + 3 + 7 + 8 + 101
b = a * 3 / 5
c = b * 4 / 8
print(c)
age1 = 12
age2 = age1
age3 = age2
age2 = 23
print(age1, age2, age3 )
# Constant: A quantity that never changes. Variables that default to all uppercase are constants.
# ID number
# Notes: Help you understand other people's codes.
# Single line comment: # '''Commented content''' """Commented content"""
# Basic data type:
print('This is a string'

msg = '''The bright moonlight in front of the bed
is suspected to be frost on the ground.
'''
print(msg)

# connector
msg1 = 'old boy education'
msg2 = 'is the best training institution'
print(msg1 + msg2)
msg ​​= 'strong'
print(msg * 8)

# bool value True False two State: determine the authenticity of the code.
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:





if name == 'Your Highness':
print('Old iron, no problem')
else:
print('If you are sick....')


#if elif ...
num =int(input('Please input your Choice: ')) #str--->int str All consist of numbers
if num == 4:
print('I will have lunch')
elif num == 5:
print('I will have dinner')
elif num == 6:
print('Healthcare, go')


#if elif ... else
num =int(input('Please enter your choice:')) #str--->int str All consist of numbers
if num = = 4:
print('Lunch, please')
elif num == 5:
print('Dinner, please')
elif num == 6:
print('Health care, let's go')
else:
print('Give you a chance I can't catch it....')


#Nested
num1=input('Please enter a number')
if num1 =='3':
num2=input('Please enter a number:')
if num2 == '5':
print('You can guess right')
else:
print('Keep trying')

score = int(input("input score"))
if score>100:
print("I wipe, The highest score is 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 loop #while
condition:
# Result

while True:
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('凉凉')
flag=False
print('第一次')

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 = 0
while count<101:
if count%2 ==0:
print(count)
count=count+1

#break continue 打断循环

while True:
print(111)
print(222)
break
print(333)
print(666)


while True:
print(111)
print(222)
continue
print(333)
print(666)
'''

# break while 循环 计算出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=324975610&siteId=291194637