python full stack -day1

1. What is compiled and interpreted?

  Compiled: all-time code is compiled into a binary file. (C, c ++)

    Advantages: high operating efficiency.

    Disadvantages: slow development, can not be cross-platform.

  Interpreted: When the program runs, explain line by line from top to bottom into a binary file.

    Advantages: the development of high speed, high efficiency, cross-platform.

    Cons: low operating efficiency.

2, the difference in python2x and macro python3

  Repeat rate python2x source, not standardized, simple and elegant python advocating clear, so creating a python3, more standardized.

3, python2 Chinese will display an error

 Solution: # - * - encoding: utf-8 - * - (must be placed in the first line of code)

4, variables, constants and notes

   Variables: any combination of alphanumeric underscores, and can not begin with a digit having descriptive not python with the keyword , the Chinese can not pinyin.

  Constant: convention, can not be changed, all uppercase letters.

  Notes: single-line comments -> #  

     Multi-line comments -> '' '......' '' or "" "......" ""

keywords python 33

'False', 'None', 'True', 'and', 'as','assert', 'break', 'class', 'continue', 

'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 

'import','in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise','return', 

'try','while', 'with', 'yield'

5, user interaction (input)

  1. Wait for input

  2. Place the contents of your input is assigned to the current variable

  3.input data type out all str

= the INPUT name ( ' Please enter the name: ' ) 
Age = the INPUT ( ' Please enter ages: ' )
 IF name == ' little two ' :
     IF Age == ' 18 ' :
         Print (666 )
     the else : Print (333 )
 the else : Print ( ' error ... ' )
name = the INPUT ( ' Please enter your name: ' ) 
Age = the INPUT ( ' Please enter your age: ' )
 # Print (name, Age) 
Print ( ' My name is ' + name, ' my age ' Age + + ' years old ' )

6, the basic data type Initial

        ps: type () ---- >> View data types, () fill in the name of the data you want to see

  Boolean type (bool): True, False

  String Type: str (quoted is str, may be added to the string stitched together, may be multiplied with the digital)

  Digital Type: int (+ - * /% // **)   

          Numbers in the range: 32: 31 ~ -2 ** 2 ** 31-1

               # 64: -2 ** 63 to 2 ** 63-1

  String into digital: int (str) Condition: str must be numbers.

  Is converted into a digital string: str (int)

7, flow control statements if 

(1) if the condition: Results

print(111)
if True :
    print(666)
print(777)

(2)if  else

 

IF 4> 3 :
     Print ( ' I ask you to drink ' )
 the else :
     Print ( ' Hexibeifeng ' )

(3)if elif elif else

. 1 NUM = INPUT ( ' pro-enter your numbers: ' )
 2  IF NUM == STR (. 1 ):
 . 3      Print ( " drink together ' )
 . 4  elif NUM == STR (2 ):
 . 5      Print ( ' with smoking ' )
 6  elif NUM == str (3 ):
 7      Print ( ' opened a new, take a look at ' )
 8  the else :
 9      Print ( ' You guess wrong, ha ha !! ' )
 10  
11Score = int (INPUT ( ' Enter your score: ' ))
 12 is  IF Score> = 90 :
 13 is      Print ( ' A ' )
 14  elif Score> = 80 :
 15      Print ( ' B ' )
 16  elif Score> = 60 :
 . 17      Print ( ' C ' )
 18 is  the else :
 . 19      Print ( ' dumb ... ' )
Multiple choice

(4) if nested

= the INPUT name ( ' Please enter the name: ' ) 
Age = the INPUT ( ' Please enter ages: ' )
 IF name == ' little two ' :
     IF Age == ' 18 ' :
         Print (666 )
     the else : Print (333 )
 the else : Print ( ' error ... ' )

8, loop while

while conditions:

  result

Print ( ' 111 ' )
 the while True:
     Print ( ' not like us ' )
     Print ( ' in the world ' )
     Print ( ' itch ' )
 Print ( ' 222 ' )

The end of the while loop method:

  1. Change conditions 

count = 1
flag = True
#标志位
while flag:
    print(count)
    count = count + 1  
    if count > 100 :
        flag = False

count = 1
while count <= 10:
    print(count)
    count += 1
Changing conditions

  2.break (out of the while loop)

print('111')
while True:
    print('222')
    print('333')
    break
    print('444')
print('555')

count = 1
while True:
    print(count)
    count = count + 1
    if count > 100:
        break
break

  3.continue (equivalent to see continue to see the bottom while loop, that is the end of the current cycle, the next cycle start)

print('111')
count = 1
while count < 20:
    print(count)
    continue
    count = count + 1
continue

9, exercise

sum = 0
count = 1
while count <= 100:
    sum += count
    count += 1
print(sum)
#1+2+...+100
#方法一
count = 1
while count < 101:
    print(count)
    count += 2
#方法二
count = 1
while count < 100:
   count += 1
   if count %2 == 1:
       print(count)
#方法三
count = 1
while count < 100:
    count += 1
    if count %2 == 0:
        continue
    print(count)
# 1-100 all the odd output
count = 0
while count < 100:
    count += 1
    if count % 2 != 0:
       continue
    print(count)
# 1-100 output of all even
count = 0
while count < 10:
    count += 1
    if count == 7:
        pass
    else:
        print(count)
# While loop input 1234568910
count = 1
sum = 0
while count < 100:
    if count %2  == 1:
        sum = sum + count
    else:
        sum = sum - count
    count += 1
print(sum)
# Seeking 1-2 + 3-4 + 99 ... and all the numbers
= I 0
 the while I <. 3 : 
    username = INPUT ( ' Enter account number: ' ) 
    password = int (INPUT ( ' Enter password: ' ))
     IF username == ' Wang '  and password == 1234 :
         Print ( ' Login successful ' )
         BREAK 
    the else :
         Print ( ' Login failed, please log in again ' ) 
    i + = 1
 Print ( ' password locked ' )
# Log (three retries opportunity)

 

Guess you like

Origin www.cnblogs.com/dabj-yb/p/12431437.html