Python job 01

Source: Internet
Author: User
Tags python script


1, compiled language before the application source execution, you need to compile the program source code into a hardware platform can be directly operational binary machine code, compiled binary executable files can only run on the corresponding platform. Therefore, it does not rely on the interpreter, the execution efficiency is high, the cross platform is poor.
Common compiled languages: C, C + +, go, rust, etc.

The interpretive language is translated into machine language with the corresponding language interpreter and executed on one side. Cannot generate executable files that can be executed independently and cannot be detached from the interpreter. Therefore the execution speed is slow, relies on the interpreter to run, the cross-platform is good.
Common interpreted languages: Python, PHP, Java, PHP, Ruby, etc.

2. How Python scripts are executed
The first is to write code in the interactive mode of entering the Python interpreter
The second is to set the Python interpreter environment variable and edit the Python script.
Python + script file execution script.

3. Python single-line comment use before row #
# Python comments
Python multiline comments using triple quotes
”“”
Multi-line comments
Triple Multi-Quote
“”“
‘’‘
Multi-line comments
Triple Single quotation mark
’‘’

4, the Boolean value is divided into true and false two kinds

5. Declaring variables requires attention to the first rule of variables:
1) can only be a combination of letters, numbers, or underscores
2) The first character cannot be a number
3) keyword cannot be feared as variable name

6. View variables in memory address: ID (object)

    " HQs "    Print ID (a)

You can view the memory address of variable A.

7.

(1) Enter the user password, u:seven,p:123 log on successfully, otherwise the login failed.

1 #-*-conding:utf-8-*-2 Print("Login to XXX platform")3U = input ("Please enter user name:")4p = input ("Please enter your password:")5 ifU = ='Seven'  andp = ='123':6     Print("Login Successful")7 Else:8     Print("Logon Failure")

(2) Allow repeated input three times when failed

1 #-*-coding:utf-8-*-2n =03  whileN < 3:4     Print("Login to XXX platform")5U = input ("Please enter user name:")6p = input ("Please enter your password:")7n + = 18     ifU = ='Seven'  andp = ='123':9         Print("Login Successful")Ten          Break One     Else: A         Print("Logon Failure")

(3) Username seven or Alex, password 123, allow repeat input three times on failure

1 #-*-coding:utf-8-*-2n =03  whileN < 3:4     Print("Login to XXX platform")5U = input ("Please enter user name:")6p = input ("Please enter your password:")7n + = 18     if(U = ='Seven' orU = ='Alex') andp = ='123':9         Print("Login Successful")Ten          Break One     Else: A         Print("Logon Failure")


8.
A, using while implementation 2-3+4-5+6-... +100

  1  #  -*- Coding:utf-8-*-  2  n = 2 3  sum = 0   4  while  N     <= 100:   5  if  n%2 == 0:   6  sum += n   7  else  :   8  sum-= n   9  n + = 110  print  (sum) 


B, using the while loop output 1,2,3,4,5,7,8,9,11,12
#-*-coding:utf-8-*-
# using while loop output 1,2,3,4,5,7,8,9,11,12
# I don't see the law.
N = 0
while n <=:
    n + = 1
    if n = = 6 or n ==10:
   ;      Pass
    else:
        Print (n,end= " ")   # Horizontal output

D, output 1-100 inside odd using while implementation

# -*-coding:utf-8-*- # use while loop output 1-100 inside odd number n = 0 while n <:    if n% 2 = = 0:         + = 1    else:        print(n,end="")        + = 1


E, using the while output 1-100 even

1 #-*-coding:utf-8-*-2 #using the while loop to output 1-100 inside odd number3n =04  whileN < 100:5     ifn% 2 = = 0 andn!=0:6         Print(n,end=" ")7n + = 18     Else:9n + = 1


9, N1 and N2 use the same memory address, only the variable name is different

Python job 01

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.