Article From:https://www.cnblogs.com/louis0815/p/9062656.html

PythonBasics

    First, the first sentence of Python code

      (LinuxThe system creates a hello.py file in the /home/dev/ directory, which reads as follows:

1
print "hello,world"

      Execute the hello.py file, namely:python /home/dev/hello.py

      Suffix name can be arbitrary, but when the program is more complex, the file import module, the suffix name is not py, easy to make mistakes.

      Later, the name of the file suffix is PY

 

      pythonThe internal execution process is as follows:

        

    Two, interpreter (Python code two ways of execution)

      a)First, when we executed Python /home/dev/hello.py hello.py in the previous step, we explicitly pointed out that the hello.py script was executed by the Python interpreter.

       If you want to execute Python scripts as well as executing shell scripts, case:./hello.py ,So it needs to beThe header specified interpreter in the hello.py file,As follows:

1
2
3
#!/usr/bin/env python
  
print "hello,world"

       In this way, execute./hello.py You can.

        ps:Hello.py is required before execution, Chmod 755 hello.py

      b)Second, enter the Python interpreter, input the code directly, output the result.

      • windowsSystem, command prompt, enter python, enter the Python interpreter.

    

    Three, annotated

      Stare

      Multi line annotation: “” “annotated content” “”

    

    Four. Execution of operation

        inputUse

        Wait forever, until the user enters the value

        input(“Please enter the username.

        Assign the input value to the n

        n = input(“Please enter the username.

 

    Five. Basic data types

      Character string

        Content in quotation marks

        Addition:

          n1=“alex”

          n2=“sb”

          n3=n1+n2

          n3=“alexsb”

        Multiplication:

          n1=“alex”

          n2=n1*3

          n2=”alexalexalex”

      

       number

        Addition, subtraction, multiplication, and division

        Sub Party: * * *

        %:Get the remainder

             temp = a % 2

          if temp = 0

            print(“Even number “)

          else

            print(“Odd number “)

        //:The integer part of a quotient

           

Leave a Reply

Your email address will not be published. Required fields are marked *