python
Birth:
The founder of Python is Guido van Rossum (Uncle Tortoise)
comparison of python2x and python3x:
PYTHON2X: Source code is not standardized, source confusion, duplicate code more, PYTHON2X: The default encoding method ascii,python2x not support Chinese, display Chinese first line to add:-*-Encoding:utf-8-
*-
Python3x: Re-source code, code specification, beautiful, clear, simple
Variable:
# variable: Stores the calculated intermediate results for subsequent code use.
Variable setting rules:
1, must be a letter, numeric underline any combination.
2, cannot be the beginning of a number.
3, 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 ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ',
' Raise ', ' return ', ' try ', ' while ', ' with ', ' yield ']
4, the variable cannot be in Chinese.
5, the variable cannot be too long.
6, variables have a descriptive nature.
Ageofoldboy = 56
Numberofstudents = 80
# Underline
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)
# variable: Stores the calculated intermediate results for subsequent code use.
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: The amount that remains constant. The default all uppercase variable is a constant.
# ID Number
# Comment: help you understand someone else's code.
# single Comment: # "Annotated Content" "" "Annotated Content" "
# Underlying data type:
Print (' This is a string ')
Print ("This is a string")
msg = ' Bed fore Moonlight,
Suspicion is ground frost.
‘‘‘
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 states: The Judgment code is true or FALSE.
Print (3 > 2)
Print (3 > 4)
Print (' True ')
Print (True)
# Determine what the data type of this object is ()
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
# Separate if
‘‘‘
Print (111)
If 3>2:
Print (666)
Print (333)
#if Else
Name=input (' Please enter your name: ')
If name = = ' Rajah ':
Print (' Old iron, no problem ')
Else
Print (' ill-treated ... ')
#if elif ...
Num =int (Input (' Please enter your choice: ') #str--->int str is all made up of numbers
if num = = 4:
Print (' Lunch me Please ')
elif num = = 5:
Print (' Dinner me Please ')
elif num = = 6:
Print (' Big health, walk up ')
#if elif. Else
Num =int (Input (' Please enter your choice: ') #str--->int str is all made up of numbers
if num = = 4:
Print (' Lunch me Please ')
elif num = = 5:
Print (' Dinner me Please ')
elif num = = 6:
Print (' Big health, walk up ')
Else
Print (' Give you a chance to catch ... ')
#嵌套
Num1=input (' Please enter a number ')
if num1 = = ' 3 ':
Num2=input (' Please enter Number: ')
if num2 = = ' 5 ':
Print (' This all can guess right ')
Else
Print (' Keep trying ')
score = Int (input ("Enter fraction"))
If score>100:
Print ("I rub, 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 Cycle
#while conditions:
# results
While True:
Print (' loyalty ')
Print (' Pink Memories ')
Print (' cool ')
Flag=false
Flag = True
While flag:
Print (' 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 = 0
While count<101:
If count%2 ==0:
Print (count)
Count=count+1
#break Continue interrupt Loop
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 calculates the 1+2+3+4....+100
Count = 1
sum = 0
While True:
sum = sum + count
Count = Count + 1
if count = = 101:break
Print (sum)
Python---Basics