Python Learning notes (0)

Source: Internet
Author: User
Tags first string unsupported

What type of language is Python?

Python is a scripting language

Python:https://www.python.org/downloads/

Python version: Python 3.4.2-64bit

The scripting language (Scripting language) is a computer programming language and therefore allows developers to write programs that give computers orders to act. Getting things done quickly and easily in a simple way is often an important principle in creating scripting languages, and based on this principle, scripting languages are often easier to use than system programming languages such as C, C + +, or Java.
Also let the scripting language have some features that are part of the scripting language:

  • Syntax and structure are usually relatively simple
  • Learning and using is usually relatively simple
  • Usually it is easy to modify the "interpretation" of the program as a way of running, without the need to "compile"
  • Program development capacity is better than running performance

    A script can automate the interaction that would otherwise be done with the keyboard. A shell script consists primarily of commands that would otherwise need to be entered at the command line, or in a text editor where users can use scripts to combine common operations into a set of serial. The language used primarily to write this script is called a scripting language. Many scripting languages have actually exceeded simple user command serial instructions and can also write more complex programs.

    What is IDLE?

    Idle is a python shell,shell means "shell", basically, is a way to interact with the program by typing text! Like our Windows cmd window, a black command window like Linux, they're all shells, and using them, we can give commands to the operating system. Similarly, we can use the idle shell to interact with Python. Once you've installed Python, searching directly for idle is displayed.

    Open idle and see ">>>" This prompt, "it" means to tell us that Python is ready, waiting to type Python instructions.

    We can try typing the instructions:

    >>> Print ("I Love Python")

    As you can see, Python's Idle directly prints the string I love Python

    You can try typing the wrong command:

     >>>  System.out.println (" Span style= "COLOR: #800000" >i love Python   "  ); Traceback (most recent): File    <pyshell#1>  , Line 1, in  < Module> System.out.println (  " i love Python   " ) Nameerror:name   " system   " is  not  defined 

    found that the idle directly to our error, and very friendly to remind us that Nameerror:name ' System ' is not defined,system this thing does not define

    Try typing the Python2 syntax:

    Print " I Love Python "  in'print'

    It will tell us that it is a wrong syntax.

    Typing a lot of wrong information, try typing the correct information, such as calculation:

    Print (5 + 8)13

    In idle, the print calculation can even be printed without the print () function, which can be directly entered into a numeric calculation, such as:

    # Add >>> 5 + 813#  subtract, and output negative >>> 5-8-3#  Subtract, the output is positive >>& Gt 9-54#  Multiply >>> 2 *# Division , output is a floating-point decimal number >>> 9/33.0#  If To output a positive number, use two division sign "//">>> 9//33

    Not only can it be used as a calculator, but it can also handle very large numerical computations:

    >>> 1234567890123456789 * 987654321098765432112193263113702179522374638011112635269

    It can also be used to add strings:

    #Add a String>>>'I'+' Love'+'Python''Ilovepython'#The string is too ugly to add, we add a space after the word>>>'I'+' '+' Love'+' '+'Python'+'!''I Love python!'#add Chinese and English>>>"I'm"+"Love"+"Python"'I love Python .'

    Python is not just a concatenation and addition of strings, it can also be multiplied with strings:

    " * 3"

    Of course, not all strings can be multiplied, such as the string multiplied by the string, will be error, Python is not so only, the string division, subtraction will be error:

    #string and number added, error>>>'I Love Python'+ 5Traceback (most recent): File"<pyshell#7>", Line 1,inch<module>'I Love Python'+ 5Typeerror:can'T Convert'Int'object to str implicitly#string multiplied by string, error>>>'I Love python!'*' Love'Traceback (most recent): File"<pyshell#40>", Line 1,inch<module>'I Love python!'*' Love'Typeerror:can't multiply sequence by non-int of type'Str'#string subtraction, error>>>'I Love python!'-' Love'Traceback (most recent): File"<pyshell#41>", Line 1,inch<module>'I Love python!'-' Love'typeerror:unsupported operand type (s) for-:'Str'  and 'Str'#Divide the string, error>>>'I Love python!'/3Traceback (most recent): File"<pyshell#42>", Line 1,inch<module>'I Love python!'/3typeerror:unsupported operand type (s) for/:'Str'  and 'int'

    Why >>>print (' I love fishc.com ' * 5) can execute normally, but >>>print (' I love fishc.com ' + 5) error?

    In Python it is not possible to add two completely different things, such as numbers and text, for this reason that >>>print (' I love fishc.com ' + 5) will not be able to make an error. It's like saying, "How much is the three-plus-god well empty?" "It doesn't make much sense, the result could be five, maybe six, or maybe eight!" But multiplying by an integer doubles it to a certain extent, and the front example is to print the string "I love Python" five times.

    What is the role of print ()?

    Having said so much, I forgot print (), so what is print ()?

    Print () displays some text in the Output window. We can enter help (print) in the idle to ask for assistance

    One of the more useful is the built-in method for print Sep and end

    Sep---Inserts a value between strings, by default a space, such as:

    #in print, each string is separated by a "," comma, and the default is a space>>>Print('I'm the first string','I'm a second string') I'm the first string I'm the second string#if I want to have two strings without spaces, I can use Sep.>>>Print('I'm the first string','I'm a second string', sep="') I'm the first string I'm the second string#Of course, you can also use other text to separate strings. >>>Print('I'm the first string','I'm a second string', sep='---I exist, just to separate you---') I was the first string of---I exist, just to separate you---I'm a second string#use commas to separate strings, in order to achieve obvious effect, the estimated extra a lot of commas ~>>>Print('I',' Love','Python', sep=',,,,,') I,,,,, love,,,,, Python#\ n is a newline character.>>>Print('I'm the first string','I'm a second string', sep='\ n') I'm the first string I'm the second string

    The end---Appends a value to the end of the string, by default a newline, such as:

    #in the idle, input print Click Enter, directly output, if you use a semicolon, you can write on a line of two instructions in the output, Python idle is not very convenient ~>>>Print('I'm on the first line! ');Print('I'm on the second line! ') I'm on the first line! I'm on the second line! #If you don't add end, the last value is \ n, but if you add a end= ', you get rid of it and turn it into an empty string, so two print can be displayed on one line.>>>Print('I'm on the first line! ', end="');Print('I'm on the second line! ') I'm on the first line! I'm on the second line! >>>Print('I'm on the first line! ', end='---Just don't let the line break---');Print('I'm on the second line! ') I'm on the first line! ---just don't let the line break---me in the second line!

    If I need to embed a double quote in a string, I can do this:

    #In "double quotes", with "double quotes" in the string, Python will think that this is the end of the sentence, thinking that the next "double quotes" to start typing the next paragraph, so ' it ' will be very understanding of the prompt you "syntax error">>>Print("I like Python very much ."It", do you like it? ") Syntaxerror:invalid Syntax#we can use the backslash to comment out the "double quotes">>>Print("python I really like \ "It \", do you like it? ") Python I like it very much"it", do you like it? #we can enter a string in ' single quotation marks ' and use double quotation marks where the string needs to be "double quotes">>>Print('python I like "it" very much, do you like it? ') Python I like it very much"it", do you like it? #of course, we can also enter single quotes in double quotes>>>Print("What ' s your name? \nmy name ' s Python") What's your name?My Name's Python

    What is the difference between input >>> ' python ' and input >>>print (' Python ')?

    The direct input is to print the result and type to the screen, while print prints the results to the screen, try it yourself and observe the results!

    # the output is quoted ' Python ' ' Python ' # output without quotation marks Print (' Python') Python

    If you are in a text editor, the problem is obvious. For example, in idle, use "Ctrl + N" To open a text editor

    print ' Python ' directly, click F5 to run and find nothing in idle

    with print (), it can be printed.

    Setting environment variables

    Set the environment variables for your operating system so that you can easily enter the Python environment

    System variables, environment variables, advanced system settings, properties, anti-key computer, and so on. Add a Python installation directory to the variable value, edit

    Set it up, type cmd in the run, enter Python, and you can test it. After executing python, it's like idle. It's just a dark window.

    Why should we use Python3?

    Why should we use Python? What the hell is wrong with Python2? It seems that many programmers are still using Python2?

    Indeed, there are quite a few programmers using Python2, but Python3 is the future of Python, just like XP and WIN7. In fact, Python3 in the new features is really wonderful, it is worth to study deeply! Feel that if you understand the Python3,python2 code reading is not a problem for you!

  • Python Learning notes (0)

    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.